Created
December 4, 2017 17:27
-
-
Save hoanbka/141fc5a3632b81ea2e70197cba42ce70 to your computer and use it in GitHub Desktop.
cans of cola
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<iostream> | |
| #include<vector> | |
| using namespace std; | |
| int main() { | |
| long long n; | |
| cin >> n; | |
| vector<long long> a; | |
| vector<long long> b; | |
| a.resize(n); | |
| b.resize(n); | |
| for (int i = 0; i < n; i++) cin >> a[i]; | |
| for (int i = 0; i < n; i++) cin >> b[i]; | |
| long long remainingTotal = 0; | |
| long long max1 = 0; | |
| long long max2 = 0; | |
| for (int i = 0; i < n; i++) { | |
| remainingTotal += a[i]; | |
| if (b[i] > max1) { | |
| max2 = max1; | |
| max1 = b[i]; | |
| } else if (b[i] > max2) { | |
| max2 = b[i]; | |
| } | |
| } | |
| if (remainingTotal > max1 + max2) { | |
| cout << "NO"; | |
| } else cout << "YES"; | |
| return 0; | |
| } | |
| // 5 5 0 | |
| // 5 5 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment