Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 51519    Accepted Submission(s): 17609

Problem Description
Nowadays, we all know that Computer College is 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 is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
 
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- 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 that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
 
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
 
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
 
Sample Output
20 10
40 40
 
Author
lcy
 

代码:

 #include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int val[N],dp[N];
int main(){
int n,a,b,len,sum;
while(~scanf("%d",&n),n>){
memset(dp,,sizeof(dp));
memset(val,,sizeof(val));
len=;sum=;
for(int i=;i<n;i++){
scanf("%d%d",&a,&b);
while(b--){
val[len++]=a;
sum+=a;
}
}
for(int i=;i<len;i++){
for(int j=sum/;j>=val[i];j--){
dp[j]=max(dp[j],dp[j-val[i]]+val[i]);
}
}
printf("%d %d\n",sum-dp[sum/],dp[sum/]);
}
return ;
}

最新文章

  1. 电脑缺少**.dll文件
  2. Log4j2 - 配置
  3. 特殊的ASCII码对应的字符
  4. Vs2010工具栏显示“开始执行“按钮
  5. StringGrid 实例3: 本例功能: 1、修改 TStringGrid的默认宽与高; 2、添加行; 3、确认当前单元并赋值.
  6. jsp、js分页功能的简单总结
  7. js的动态加载、缓存、更新以及复用
  8. 从你的u盘启动:30天自制操作系统第四天u盘启动学习笔记
  9. shuffle() 函数(转)
  10. 大数据笔记07:大数据之Hadoop的HDFS(特点)
  11. python 网络编程第二版
  12. 西南民大oj(递推)
  13. MySQL中group_concat函数-和group by配合使用
  14. 【转】js/jquery中刷新iframe方法(兼容主流)
  15. iOS 通过UIControl,自定义控件
  16. datatable 添加列之前判断是否存在该列
  17. 《笨方法学Python》加分题33
  18. 修改docker image存放位置
  19. 使用AsyncTask类实现简单的异步处理操作
  20. ES6 Number

热门文章

  1. 常见排序算法题(java版)
  2. 发送广播重新挂载SD卡,使图库可以及时显示自己保存的图片(无需手机重启)
  3. 玩转Linux之pwd命令
  4. Swift 与众不同的地方
  5. 在Linux下安装ArcGIS10.2
  6. vue常用片段
  7. hnust 分蛋糕
  8. 爬虫:Scrapy10 - Link Extractors
  9. hdu 1811 Rank of Tetris (拓扑 &amp; 并查集)
  10. BZOJ 1731: [Usaco2005 dec]Layout 排队布局