Welcome to the--bestcoder Anniversary (High quality topic + multiple Rewards)
Big Event in HDU
Time limit:10000/5000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 28468 Accepted Submission (s): 10023
Problem Descriptionnowadays, we all know that computer College are the biggest department in HDU. But, maybe you don ' t know that computer College had ever been split into computer College and software College in 2002.
The splitting is absolutely a big event in hdu! At the same time, it's a trouble thing too. All facilities must go halves. First, all facilities is assessed, and the facilities is thought to being same if they has the same value. It is assumed this there is N (0<n<1000) kinds of facilities (different value, different kinds).
Inputinput contains multiple test cases. Each test case is starts with a number n (0 < n <= – The total number of different facilities). The next N lines contain an integer V (0<v<=50--value of facility) and an integer M (0<m<=100--corresponding Number of the facilities) each. You can assume this all V is different.
A test case starting with a negative an integer terminates input and this test case was not the be processed.
Outputfor, print one line containing, integers A and B which denote the value of computer College and Softwar e College'll get respectively. A and B should be as equal as possible. At the same-time, you should guarantee, which A is not less than B.
Sample Input210 120 1310 1 20 230 1-1
Sample OUTPUT20 1040 40
Authorlcy
Recommendwe carefully selected several similar problems for you:2602 1203 2159 2955 2844
#include <stdio.h>#include<string.h>intc[250005],temp[250005];intnum[ -],cost[ -];intMain () {intN; while(SCANF ("%d", &n)! =EOF) { if(n<0) Break; Memset (c,0,sizeof(c)); memset (temp,0,sizeof(temp)); memset (num,0,sizeof(num)); memset (Cost,0,sizeof(cost)); intsum=0; for(intI=0; i<n;i++) {scanf ("%d%d",&cost[i],&Num[i]); Sum+=cost[i]*Num[i]; } inttotal=sum/2; for(intI=0; i<=num[0];i++) {C[i*cost[0]]=1;. Special attention when initializing} for(intI=1; i<n;i++){ for(intj=0; j<=sum;j++){ for(intk=0; k+j<=sum&&k/cost[i]<=num[i];k+=Cost[i]) temp[k+j]+=C[j]; } for(intIi=0; ii<=sum;ii++) {C[ii]=Temp[ii]; TEMP[II]=0; } } inti; for(i=total;i>=0; i--){ if(C[i]) Break; } printf ("%d%d\n", sum-i,i); } return 0;}
HDU 1171 Big Event in HDU