Title Link: Https://cn.vjudge.net/problem/CodeForces-892A
Jafar has n cans of cola. Each can be described by integers:remaining volume of cola ai and can ' s capacity b< /c7>i (ai ? ≤?) bi).
Jafar have decided to pour all remaining cola into just 2 cans, determine if he can does 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).
Example
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
The Thief Jr Water, does not need to be solved at all ...
Just want to put a record O (n) get the maximum and minor in the array for loop code, lest later when the brain to forget the next not come out stiff ...
#include <bits/stdc++.h>using namespaceStd;typedefLong LongLL;intN;intMain () {scanf ("%d",&N); LL sum=0; for(intI=1, tmp;i<=n;i++) {scanf ("%d",&tmp); Sum+=tmp; } LL max1=-1, max2=-2; for(intI=1, tmp;i<=n;i++) {scanf ("%d",&tmp); if(Max2<=max1 && max1<=tmp) max2=max1,max1=tmp; Else if(max2<tmp && tmp<=max1) max2=tmp; } if(max1+max2 >= sum) cout<<"YES"<<Endl; Elsecout<<"NO"<<Endl;}
Codeforces 892a-greed-[Super Flood Problem][o (n) array Max and sub-large]