#P9637. 「yyOI R1」youyou 的篡改(Hard Ver.)
「yyOI R1」youyou 的篡改(Hard Ver.)
Background
The Easy Version and the Hard Version differ only in the final required output; all other statements are identical.
Problem Description
youyou is going to hold a contest. There are problems in this contest, and each problem has a difficulty value .
youyou gives a counting parameter . He thinks that, for the -th problem, its solvability should be the sum of the difficulty values of the hardest problems among problems to , after sorting their difficulty values in increasing order.
Since problems to are too easy, youyou does not want to consider the solvability of these problems.
Then the total solvability of this contest is the sum of solvability from problem to problem , that is, the value of .
He can tamper with the difficulty of problem and change it to any positive integer.
Given that the total solvability must lie within the interval , how many possible values can the total solvability take?
Input Format
The first line contains five positive integers .
The second line contains integers, where the -th integer is the difficulty value of the -th problem.
Output Format
Output one integer in a single line, indicating the number of possible values of the total solvability under the constraints.
5 1 1 5 10
1 2 2 2 2
2
Hint
Sample Explanation #1
You can modify , and .
When the first number is changed to , the total difficulty is .
When the first number is changed to , the total difficulty is .
Only these two values satisfy the requirement, i.e. the total difficulty equals or . Therefore, the answer is .
Constraints
This problem uses Subtasks. For each Subtask, you need to pass all test points to get the score for that part.
| Subtask ID | Score | |
|---|---|---|
For of the testdata, , , .
Translated by ChatGPT 5