Codeforces Round #311 (Div. 2) A. Ilya and Diplomas

题目链接:http://codeforces.com/contest/557/problem/A

#include <iostream>

using namespace std;
int minn[3];
int maxx[3];
int main()
{
    int m;
    while(cin>>m)
    {
        int ans[3]={0};
        for(int i=0; i<3; i++)
            cin>>minn[i]>>maxx[i];
        for(int i=0; i<3; i++)
            ans[i]=minn[i];
        m-=(minn[0]+minn[1]+minn[2]);
        for(int i=0; i<3; i++)
        if(m)
        {
            if(ans[i]+m<=maxx[i])
            {
                ans[i]+=m;
                m=0;
            }
            else
            {
                ans[i]=maxx[i];
                m-=(maxx[i]-minn[i]);
            }
        }
        for(int i=0; i<2; i++)
            cout<<ans[i]<<" ";
        cout<<ans[2]<<endl;
    }
    return 0;
}

你可能感兴趣的:(水)