POJ 2014

#include <iostream>
using namespace std;

int main()
{
    //freopen("acm.acm","r",stdin);
    int len;
    int l;
    int w;
    int ans_l;
    int ans_w;
    int tem_l;
    int tem_w;
    while(cin>>len,len)
    {
        ans_l = 0;
        ans_w = 0;
        tem_l = 0;
        tem_w = 0;
        while(cin>>l>>w)
        {
            if(l == -1 && w == -1)
            {
                break;
            }
            if(tem_l + l <= len)
            {
                tem_l += l;
                if(w > tem_w)
                {
                    tem_w = w;
                }
            }
            else
            {
                ans_w += tem_w;
                if(tem_l > ans_l)
                {
                    ans_l = tem_l;
                }
                tem_w = w;
                tem_l = l;
            }
        }
        if(tem_l > ans_l)
        {
            ans_l = tem_l;
        }
        ans_w += tem_w;
        cout<<ans_l<<" x "<<ans_w<<endl;
    }
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

POJ 2014

技术网站地址: vmfor.com