A - Valera and Plates CodeForces - 369A

题意:有m个碗,k个碟子,现在有n天计划,如果计划是1,那么要用一个碗,如果计划是2,用碗或者碟子都可以

思路:能用碗的先用碗,然后再用碟子。直到2个都用完。

数据分析:1 ≤ n, m, k ≤ 1000

复杂度分析: O(n)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    int n,m,k;
    cin >>n >> m >> k;
    int b=m,p=k;
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        int x;
        scanf("%d",&x);
        if(x==1)
        {
            if(b!=0)    b--;
            else    ans++;
        }
        else if(x==2)
        {
            if(p!=0)    p--;
            else
            {
                if(b!=0)    b--;
                else    ans++;
            }
        }

    }
    cout << ans << endl;
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务