Hdu 5364 (bc#50 1001) Distribution Money

Source: Internet
Author: User

Distribution Money

Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 276 Accepted Submission (s): 163


Problem Descriptionafa want to distribution she money to somebody. She divide her money into n same parts. One who want to get the money can get more than one part. But if one man's money was more than the sum of all others '. He Shoule be punished. Each one of the get a part of the money would write down his ID on the that part.

Inputthere is multiply cases.
For each case,there are a single integer n (1<=n<=1000) on first line.
In second line,there was n integer a1,a2...an (0<=ai<10000) AI is the the-the-ith man ' s ID.

Outputoutput ID of the man should is punished.
If Nobody should be punished,output-1.

Sample Input31 1 242 1 4 3

Sample output1-1

Sourcebestcoder Round #50 (Div.2) water. When the game was stupid, two rounds, mom. Break ... .
/************************************************************************* > File name:code/bc/#50/1001.cpp & Gt AUTHOR:111QQZ > Email: [email protected] > Created time:2015 August 08 Saturday 19:02 16 seconds ************************* ***********************************************/#include<iostream>#include<iomanip>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<string>#include<map>#include<Set>#include<queue>#include<vector>#include<stack>#defineY0 ABC111QQZ#defineY1 HUST111QQZ#defineYn hez111qqz#defineJ1 CUTE111QQZ#defineTM CRAZY111QQZ#defineLR DYING111QQZusing namespacestd;#defineREP (i, n) for (int i=0;i<int (n); ++i)typedefLong Longll;typedef unsignedLong LongULL;Const intINF =0x7fffffff;intcnt[10005];intN;intx;intMain () { while(SCANF ("%d", &n)! =EOF) {    BOOLFlag =false; memset (CNT,0,sizeof(CNT));  for(inti =0; I < n; i + +) {scanf ("%d",&x); CNT[X]++; if(flag)Continue; if(cnt[x]>n/2) {flag=true; cout<<x<<Endl; }    }    if(!flag) {cout<<-1<<Endl; }    }    return 0;}

Hdu 5364 (bc#50 1001) Distribution Money

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.