#P4343. [SHOI2015] 自动刷题机
[SHOI2015] 自动刷题机
Description
The way the automatic problem-solving machine works is very simple: it instantly figures out the correct solution to a problem, then starts writing code. Every second, the code generation module has two possible outcomes:
- It writes lines of code.
- In a bad mood, it deletes lines of previously written code. (If is greater than the current code length, this is equivalent to deleting everything.)
For an OJ, there is a fixed positive integer length . Once the machine has accumulated at least lines of code at the end of a second, it will automatically submit and AC the problem, then create a new file (i.e., discard all previous code) and start the next problem. SHTSC ran the machine on an OJ for one day and obtained many log entries about code writing. He suddenly realized he did not record what on this OJ actually is. Fortunately, from his Rank on the OJ, he knows the machine solved problems in total. Please compute the minimum and maximum possible values of .
Input Format
The first line contains two integers , indicating that the machine produced log entries and solved problems in total.
The next lines each contain an integer , describing each log entry in order. If , it means lines of code were written. If , it means lines of code were deleted.
Output Format
Output one line with two integers, representing the minimum and maximum possible values of .
If no such exists, output one line with a single integer .
4 2
2
5
-3
9
3 7
Hint
Constraints
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , and fits in the range of
int.
Translated by ChatGPT 5
京公网安备 11011102002149号