zl程序教程

您现在的位置是:首页 >  其它

当前栏目

【Codeforces Round #446 (Div. 2) A】Greed

Codeforces div round
2023-09-14 09:03:45 时间

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

贪心选容量大的瓶子就好

【代码】

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5;

int n;
int a[N+10],b[N+10];

main(){
	#ifdef LOCAL_DEFINE
	    freopen("F:\\c++source\\rush_in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n;i++){
		cin >> a[i];
	}
	for (int i = 1;i <= n;i++){
		cin >> b[i];
	}

	sort(b+1,b+1+n);
	int rest = b[n] + b[n-1];
	for (int i = 1;i <= n;i++){
		if (rest>=a[i]){
		 	rest-=a[i];
		}else return cout << "NO"<<endl,0;
    }
    cout << "YES"<<endl;
	return 0;
}