#P17442. 掐头去尾 / Delete and Backspace
掐头去尾 / Delete and Backspace
Problem Description
You are given an array of length . For each , consider the following process independently.
Initially, the array is . You must perform exactly operations. In each operation, you may choose one of the following:
- Backspace: delete the first element of the current array.
- Delete: delete the last element of the current array.
Your score is defined as the value of the element deleted in the -th operation.
For each , find the maximum score you can obtain.
Input Format
The first line contains an integer , the length of the array ().
The second line contains integers , representing the array ().
Output Format
Output integers. The -th integer should be the maximum score achievable when performing exactly operations.
5
2 7 8 1 4
4 7 8 8 8
Hint
For , you can only delete the leftmost or the rightmost , so the maximum score is .
For , you can delete the leftmost first, then delete the leftmost . The element deleted in the second operation is , so the maximum score is .
For , you can delete the leftmost in order, making the element deleted in the third operation , so the maximum score is .
For and , you can also arrange the earlier operations properly, so that the element deleted in the last operation is still .
Translated by ChatGPT 5