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). 

InputInput 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. 
OutputFor 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

  1. 2
  2. 10 1
  3. 20 1
  4. 3
  5. 10 1
  6. 20 2
  7. 30 1
  8. -1

Sample Output

  1. 20 10
  2. 40 40
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct De
  9. {
  10. int a,k;
  11. };
  12. De ch[];
  13.  
  14. int main()
  15. {
  16. int n,sum;
  17. while(scanf("%d",&n) && n>=)
  18. {
  19. sum=;
  20. for(int i=;i<n;i++)
  21. scanf("%d %d",&ch[i].a,&ch[i].k),sum+=ch[i].a*ch[i].k;
  22. int fb[];
  23. memset(fb,,sizeof(fb));
  24. for(int i=; i<n; i++)
  25. for(int h=;h<ch[i].k;h++)
  26. for(int j=sum/;j>=ch[i].a;j--)
  27. fb[j]=max(fb[j],fb[j-ch[i].a]+ch[i].a);
  28. printf("%d %d\n",sum-fb[sum/],fb[sum/]);
  29. }
  30. return ;
  31. }

B - Big Event in HDU的更多相关文章

  1. HDU-1171 Big Event in HDU

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  2. Big Event in HDU

    Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe ...

  3. Big Event in HDU(HDU1171)可用背包和母函数求解

    Big Event in HDU  HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1     结果是:20 10.才最均匀! 三 ...

  4. 组合数学 - 母函数的变形 --- hdu 1171:Big Event in HDU

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. HDU 1171 Big Event in HDU 多重背包二进制优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...

  6. Big Event in HDU[HDU1171]

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. HDU1171——Big Event in HDU(母函数)

    Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...

  8. Big Event in HDU(HDU 1171 多重背包)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. hdu1171 Big Event in HDU 01-背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...

  10. HDU1171-Big Event in HDU

    描述: Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don ...

随机推荐

  1. json和jquery中的ajax

    JSON: java script Object otation:js对象标记 声明一个json对象,使用key:value对应,中间用冒号连接,键值对之间用逗号连接,最外面用{}包含 声明方式: 语 ...

  2. snmp监控f5

    1.硬盘各分区使用情况 2.pool数量.vs数量 3.cpu使用率 4.内存使用率 5.电源 6.风扇 7.端口状态及流量 8.HA状态(主备情况及HA是否处于建立状态) 9.主备机同步状态

  3. NET CORE 2.0发布在IIS上提示502.5错误

    在装了WindowsHosting和NET CORE SDK后,如果没有重启服务器,访问站点报以上错误,解决办法要么重启,要么执行以下两条命令: net stop was /y net start w ...

  4. WebSocket 实现链接 群聊(low low low 版本)

    py 文件: """ 下载 gevent-websocket 0.10.1 基于Flask + geventWebSocket 建立连接,发送消息,实现群消息功能. &q ...

  5. 机器学习(四)--------逻辑回归(Logistic Regression)

    逻辑回归(Logistic Regression) 线性回归用来预测,逻辑回归用来分类. 线性回归是拟合函数,逻辑回归是预测函数 逻辑回归就是分类. 分类问题用线性方程是不行的   线性方程拟合的是连 ...

  6. scrapy 爬取前程无忧

    spider # -*- coding: utf-8 -*- import scrapy from Jobs.items import JobsItem class Job51spiderSpider ...

  7. koa 学习1

    1.搭建环境; npm init -f 2.出现错误 npm ERR!Windows_NT 6.1.7601   解决方法: npm config set proxy null npm install ...

  8. Flip String to Monotone Increasing LT926

    A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), ...

  9. pclConfig.cmake or PCLConfig.cmake

    Could not find a package configuration file provided by "pcl" (requested  version 1.8) wit ...

  10. Python建立时间事件引擎原理剖析

    作为python小白,学习量化交易的曲线是非常陡峭的,唯一好的办法就是一点点啃代码.以下代码案例来自vnpy的引擎代码. # encoding: UTF-8 #定义时间事件 EVENT_TIMER = ...