Codeforces 892a-greed-[Super Flood Problem][o (n) array Max and sub-large]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.