Select the President and choose the President for Crosstalk

Source: Internet
Author: User

Select the President and choose the President for Crosstalk

Description

James wants to be the president of the ugly nation. The Ugly nation election determines the final result based on the voting results of the States. If more than half of the States support the election, he can be elected, the voting results of each State are produced by the state's voters. If more than half of the state's voters support James, he will win the State's support. The number of voters in each State is provided. How many voters does James need to win to be elected?

Input

The input contains multiple groups of test data.
The first row of each group of data is an integer N (1 <= N <= 101), indicating the number of states in the ugly country. When N = 0, 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

Output a row of data in each group, indicating at least the number of voters James needs to win.

Sample Input

3

5 7 5

0

Sample output

6

Solution:

N States are given, with m members in each state. The n states are sorted by number of people from small to large. Each time, the m half is added to 1, and the n half is added to 1.

The Code is as follows:

 

 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 int main() 6 { 7     int a,b[110],i,j,k,q; 8     while(scanf("%d",&a),a!=0)  9     {10         memset(b,0,sizeof(b));11         for(i=0;i<a;i++)12             scanf("%d",&b[i]);13         sort(b,b+a);14         q=0;15             for(i=0;i<a/2+1;i++)16                     q+=b[i]/2+1;17         printf("%d\n",q);18     }19     return 0;20 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.