Advertisement
egormerk

Задача 27 пару из трёх

Apr 9th, 2021
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     // задача 27
  11.     // выбрать пару чисел из трёх
  12.     // чтобы она делилась на 4 и была максимальной
  13.     int n;
  14.     cin >> n;
  15.     int a, b, c;
  16.     vector <int> s(4);
  17.     vector <int> t(4);
  18.     s.resize(4);
  19.     cin >> a >> b >> c;
  20.     s[(a + b)%4] = (a + b);
  21.     s[(a + c)%4] = max(s[(a + c)%4], a + c);
  22.     s[(b + c)%4] = max(s[(b + c)%4], b + c);
  23.     for (int i = 1; i < n; i++) {
  24.         cin >> a >> b >> c;
  25.         for (int j = 0; j < 4; j++) {
  26.             if (s[j] != 0) {
  27.                 t[(s[j] + a + b)%4] = max(t[(s[j] + a + b)%4], s[j] + a + b);
  28.                 t[(s[j] + a + c)%4] = max(t[(s[j] + a + c)%4], s[j] + a + c);
  29.                 t[(s[j] + b + c)%4] = max(t[(s[j] + b + c)%4], s[j] + b + c);
  30.              }
  31.         }
  32.         s = t;
  33.         t.resize(0);
  34.         t.resize(4);
  35.     }
  36.     cout << s[0];
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement