Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int inf = 1e8;
- int main() {
- int n;
- cin >> n;
- vector<int> a(n);
- int p1 = 0, p2 = 0;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- for (int i = 0; i < n; i++)
- for (int j = i + 1; j < n; j++)
- if ((a[i] % 17 == 0 || a[j] % 17 == 0) && abs(a[i] - a[j]) % 2 == 0 && a[i] + a[j] > p1 + p2)
- p1 = a[i], p2 = a[j];
- cout << p1 << " " << p2 << endl;
- int a1 = -inf, a2 = -inf, b1 = -inf, b2 = -inf; p1 = 0, p2 = 0;
- for (int i = 0; i < n; i++) {
- int v;
- v = a[i];
- if (v % 2 == 0) {
- if (v + b1 > p1 + p2)
- p1 = v, p2 = b1;
- if (v % 17 == 0){
- if (v + max(a1, b1) > p1 + p2)
- p1 = v, p2 = max(a1, b1);
- b1 = max(b1, v);
- }
- a1 = max(a1, v);
- } else {
- if (v + b2 > p1 + p2)
- p1 = v, p2 = b2;
- if (v % 17 == 0){
- if (v + max(a2, b2) > p1 + p2)
- p1 = v, p2 = max(a2, b2);
- b2 = max(b2, v);
- }
- a2 = max(a2, v);
- }
- }
- cout << p1 << " " << p2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment