Raslboyy

Untitled

Apr 29th, 2020
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const int inf = 1e8;
  7.  
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.     vector<int> a(n);
  12.     int p1 = 0, p2 = 0;
  13.     for (int i = 0; i < n; i++)
  14.         cin >> a[i];
  15.     for (int i = 0; i < n; i++)
  16.         for (int j = i + 1; j < n; j++)
  17.             if ((a[i] % 17 == 0 || a[j] % 17 == 0) && abs(a[i] - a[j]) % 2 == 0 && a[i] + a[j] > p1 + p2)
  18.                 p1 = a[i], p2 = a[j];
  19.     cout << p1 << " " << p2 << endl;
  20.     int a1 = -inf, a2 = -inf, b1 = -inf, b2 = -inf; p1 = 0, p2 = 0;
  21.     for (int i = 0; i < n; i++) {
  22.         int v;
  23.         v = a[i];
  24.         if (v % 2 == 0) {
  25.             if (v + b1 > p1 + p2)
  26.                 p1 = v, p2 = b1;
  27.             if (v % 17 == 0){
  28.                 if (v + max(a1, b1) > p1 + p2)
  29.                     p1 = v, p2 = max(a1, b1);
  30.                 b1 = max(b1, v);
  31.             }
  32.             a1 = max(a1, v);
  33.         } else {
  34.             if (v + b2 > p1 + p2)
  35.                 p1 = v, p2 = b2;
  36.             if (v % 17 == 0){
  37.                 if (v + max(a2, b2) > p1 + p2)
  38.                     p1 = v, p2 = max(a2, b2);
  39.                 b2 = max(b2, v);
  40.             }
  41.             a2 = max(a2, v);
  42.         }
  43.     }
  44.     cout << p1 << " " << p2 << endl;
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment