SHARE
TWEET

Untitled

a guest Dec 8th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int n;
  9.     cin >> n;
  10.     vector <unsigned int> a(n);
  11.     for (int i = 0; i < n; i++) {
  12.         cin >> a[i];
  13.     }
  14.     sort(a.begin(), a.end());
  15.     unsigned int ans = 0;
  16.     for (int i = a.size() - 1; i > 0; i--) {
  17.         for (int j = i - 1; j >= 0; j--) {
  18.             if (a[i] + a[j] > ans) {
  19.                 ans = a[i] + a[j];
  20.             }
  21.             else {
  22.                 break;
  23.             }
  24.         }
  25.     }
  26.     cout << ans;
  27.     return 0;
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top