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

2
10 1
20 1
3
10 1
20 2
30 1
-1

Sample Output

20 10
40 40
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; struct De
{
int a,k;
};
De ch[]; int main()
{
int n,sum;
while(scanf("%d",&n) && n>=)
{
sum=;
for(int i=;i<n;i++)
scanf("%d %d",&ch[i].a,&ch[i].k),sum+=ch[i].a*ch[i].k;
int fb[];
memset(fb,,sizeof(fb));
for(int i=; i<n; i++)
for(int h=;h<ch[i].k;h++)
for(int j=sum/;j>=ch[i].a;j--)
fb[j]=max(fb[j],fb[j-ch[i].a]+ch[i].a);
printf("%d %d\n",sum-fb[sum/],fb[sum/]);
}
return ;
}

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. Handling Text in Python 相关命令

    s.isalpha()意思就是是不是字母,s.isdigit()意思就是是不是0-9,s.isalnum()意思就是是不是由字母和数字组成.

  2. C++ 深入理解 虚继承、多重继承和直接继承

    [摘要] 本文从5段代码实例出发,通过类中类的普通继承,类的虚继承,类的多重继承,多个虚函数类的普通继承.虚继承与多重继承,几个交叉概念,详细的阐释了继承.虚函数与虚继承的基本概念,深入剖析了继承于虚 ...

  3. df命令,du命令,磁盘分区

    df 命令 功能:用来检查linux的文件系统的磁盘空间占用情况 1. df -h 2. 以innode节点数量显示磁盘空间占用情况 df -ih 3. 列出文件系统类型 df -Th du 命令 功 ...

  4. CentOS7+CDH5.14.0安装CDH错误排查:HBase服务出现 该运行状况测试不良,因为 Service Monitor 未找到活动 Master

    错误:HBase服务出现 该运行状况测试不良,因为 Service Monitor 未找到活动 Master 如果重启服务之后无法排除该问题,请执行如下操作(CM换成自己的版本号): rm -f /o ...

  5. UML图之类图(转)

    基本概念 类图(Class Diagram): 类图是面向对象系统建模中最常用和最重要的图,是定义其它图的基础.类图主要是用来显示系统中的类.接口以及它们之间的静态结构和关系的一种静态模型. 类图的3 ...

  6. mysql中文查询问题

    alter table t_foo change `str` `str` varchar(100) character set utf8 not null ;

  7. chrome小书签-实用的小功能-javascript代码段

    1.打印页面的所有脚本引用文件及代码段: javascript:var scriptarray=document.getElementsByTagName("script");fo ...

  8. FastDFS api介绍

    1. 命令行api介绍 FastDFS提供了可用于运维测试的命令行api,下面进行介绍: 1.1 fastdfs服务管理 tracker进程服务管理脚本 /etc/init.d/fdfs_tracke ...

  9. db2数据库备份及恢复

    导出 1. 连接数据库,命令如下: db2 connect to db_name user user_name using password db_name 是指数据库的名字, user_name 是 ...

  10. AX_ClassTemplate

    static void main(Args args) { THK_InterfaceDataExtract THK_InterfaceDataExtract; FormRun formRun = a ...