且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-08-13 08:40:51

题目链接: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;
}