Advertisement
STANAANDREY

AOCMMXX d9p2

Dec 13th, 2020
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. deque<int> dq;
  4. vector<int64_t> all;
  5.  
  6. bool isOk(int x) {
  7.     for (int i = 0; i < 25; i++)
  8.         for (int j = i + 1; j < 25; j++)
  9.             if (dq[i] + dq[j] == x)
  10.                 return false;
  11.     return true;
  12. }
  13.  
  14. int main() {
  15.     freopen("text.in", "r", stdin);
  16.     for (int x, i = 1; i <= 25; i++) {
  17.         cin >> x;
  18.         dq.push_back(x);
  19.         all.push_back(x);
  20.     }
  21.     int64_t target, sum = all[0];
  22.     for (int x; cin >> x;) {
  23.         if (isOk(x)) {
  24.             target = x;
  25.             break;
  26.         }
  27.         dq.push_back(x);
  28.         dq.pop_front();
  29.         all.push_back(x);
  30.     }
  31.     cout << target << endl;
  32.     int l = 0, r = 0;
  33.     while (sum != target) {
  34.         if (sum < target) {
  35.             r++;
  36.             sum += all[r];
  37.         } else if (sum > target) {
  38.             sum -= all[l];
  39.             l++;
  40.         }
  41.     }
  42.     int64_t maxi = 0, mini = INT_MAX;
  43.     for (int i = l; i <= r; i++) {
  44.         maxi = max(maxi, all[i]);
  45.         mini = min(mini, all[i]);
  46.     }
  47.     cout << maxi + mini << endl;//*/
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement