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

题意:
两学院分设备价值,所有设备价值都算的前提下,要求第一个学院所得价值大于等于第二个学院所得价值。

思路:
记录总价值,求得总价值的一半即一个学院最多可得价值标准。记录各设备价值,排序后从大到小对比即可。
(注意小数情况)
新学到的:
使用floor函数。floor(x)返回的是小于或等于x的最大整数。 //向下取整
如:     floor(10.5) == 10    floor(-10.5) == -11
使用ceil函数。ceil(x)返回的是大于x的最小整数。       //向上取整
如:     ceil(10.5) == 11    ceil(-10.5) ==-10

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        if(n<=-1)
            break;
        int s[100005];
        double sum=0;
        int i=0;
        while(n--)
        {
            int a,b;
            cin>>a>>b;
            sum+=(double)a*b;   //记录总价值 
            while(b--)
            {
                s[i++]=a;       //价值分别存入数组 
            } 
        }
        sort(s,s+i);            //对价值排序 
        int temp=ceil(sum*1.0/2.0);//记录总价值的一半 即一个学院能获得最大价值标准 ceil向上取整
        int x=0,y=0;
        for(int j=i-1; j>=0; j--) //从大到小进行判断,价值大于temp时跳过 
        {
            if((s[j]+x)>temp)
                continue;
            x+=s[j];             //x学院所得价值 
        }
        y=sum-x;
        if(y>x)                   //确保第一个学院价值大于等于第二个学院 
            cout<<y<<" "<<x<<endl;
        else
            cout<<x<<" "<<y<<endl;
    }
}