Codeforces 892 A Greed(水题)

题目链接:点击打开链接

题目大意:现在要把所有剩余的可乐倒进2个罐子里,问能不能实现?

代码如下:

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5;
typedef long long ll;

int n;
ll a[maxn],b[maxn];
ll sum1,sum2;

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    while(cin>>n)
    {
        int i;
        sum1=sum2=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sum1+=a[i];
        }
        for(i=0;i<n;i++)
        {
            cin>>b[i];
        }
        sort(b,b+n,cmp);
        sum2=b[0]+b[1];
        if(sum1<=sum2)
            cout<<"Yes"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}




~step by step


发布了37 篇原创文章 · 获赞 23 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/zsheng_/article/details/78618991