日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

A - Greed CodeForces - 892A(水题)

發布時間:2023/12/18 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 A - Greed CodeForces - 892A(水题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can’s capacity bi (ai ?≤? bi).

Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!

Input
The first line of the input contains one integer n (2?≤?n?≤?100?000) — number of cola cans.

The second line contains n space-separated integers a1,?a2,?…,?an (0?≤?ai?≤?109) — volume of remaining cola in cans.

The third line contains n space-separated integers that b1,?b2,?…,?bn (ai?≤?bi?≤?109) — capacities of the cans.

Output
Print “YES” (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print “NO” (without quotes).

You can print each letter in any case (upper or lower).

Examples
Input
2
3 5
3 6
Output
YES
Input
3
6 8 9
6 10 12
Output
NO
Input
5
0 0 5 0 0
1 1 8 10 5
Output
YES
Input
4
4 1 0 3
5 2 2 3
Output
YES
Note
In the first sample, there are already 2 cans, so the answer is “YES”.
思路:大水題,模擬即可。只不過又忘記開long long了結果卡在第五組數據。

#include <bits/stdc++.h>//第五組數據特別大,n是1e5,num_a[i]都是1e9,不知道為什么就是過不了這組 #define ll long long//額,找到問題了,又忘記開long long 了。。。using namespace std; const int maxn = 1e5 + 5;int main() {ll n;ll num_a[maxn];ll num_b[maxn];scanf("%d",&n);ll sum = 0;for(int i = 0;i < n;i++){scanf("%lld",&num_a[i]);sum += num_a[i];}for(int i = 0;i < n;i++){scanf("%lld",&num_b[i]);}sort(num_b,num_b + n);int Max1 = num_b[n - 1];int Max2 = num_b[n - 2];if(sum <= Max1 + Max2){printf("YES\n");}else printf("NO\n");return 0; }

轉載于:https://www.cnblogs.com/tomjobs/p/10617584.html

總結

以上是生活随笔為你收集整理的A - Greed CodeForces - 892A(水题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。