#P4394. 选举
选举
Description
The residents of Byteland have recently voted in a parliamentary election. Now, as the results are announced, the parties must decide on forming a coalition government.
Each party obtains a certain number of seats in the parliament. A coalition government consists of a subset of these parties whose total number of seats is strictly greater than half of all seats. For a coalition, having more seats is better.
An excessive coalition is one in which, after removing one party from the coalition, the remaining coalition still holds a majority of seats in the parliament.
Write a program to find a coalition with the maximum possible number of seats in the parliament that is not excessive.
Input Format
The first line of standard input contains an integer , the number of parties in the election. The parties are numbered from to .
The second line contains non-negative integers separated by single spaces, where is the number of seats won by the -th party. You may assume that the total number of seats in the parliament is a positive integer not exceeding .
Output Format
Output a single integer: the maximum possible number of seats.
4
1 3 2 4
7
Hint
Sample explanation: choose the second and the fourth party.
Constraints: For all testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号