Problem description the U.S. election determines the final result based on the voting results of each State. If more than half of the States support the final result, they can be elected, the voting results in each State are produced by the state's voters. If more than half of the state's voters support Hillary Clinton, she will win the State's support. The number of voters in each State is provided. How many voters does Hillary need to win at least to be elected?
Multiple Input groups
The first row of each group of data contains an integer N (1 <= n <= 101), indicating the number of states in the United States, and n = 0 indicates that the input ends.
The next line contains n positive integers, indicating the number of voters in each state. The number of voters in each State cannot exceed 100.
Output outputs a line for each group of data, indicating that Hillary needs to win at least the number of voters
Sample Input
35 7 50
Sample output
6
# Include <iostream> using namespace STD; int main () {int N; while (CIN> N & N) {int I, j, sum = 0, T, k, a [105] = {0}; for (I = 1; I <= N; I ++) {CIN> A [I];} for (I = 1; I <n; I ++) // sort the array from small to large by the selection method {k = I; for (j = I; j <= N; j ++) {if (a [k]> A [J]) k = J;} t = A [k]; A [k] = A [I]; A [I] = T;} for (I = 1; I <= n/2 + 1; I ++) // calculate the minimum number of first few tickets, that is, sum = A [I]/2 + 1 + sum; cout <sum <Endl;} return 0 ;}