Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <fstream>
- #include <vector>
- using namespace std;
- int main() {
- // задача 27
- // выбрать пару чисел из трёх
- // чтобы она делилась на 4 и была максимальной
- int n;
- cin >> n;
- int a, b, c;
- vector <int> s(4);
- vector <int> t(4);
- s.resize(4);
- cin >> a >> b >> c;
- s[(a + b)%4] = (a + b);
- s[(a + c)%4] = max(s[(a + c)%4], a + c);
- s[(b + c)%4] = max(s[(b + c)%4], b + c);
- for (int i = 1; i < n; i++) {
- cin >> a >> b >> c;
- for (int j = 0; j < 4; j++) {
- if (s[j] != 0) {
- t[(s[j] + a + b)%4] = max(t[(s[j] + a + b)%4], s[j] + a + b);
- t[(s[j] + a + c)%4] = max(t[(s[j] + a + c)%4], s[j] + a + c);
- t[(s[j] + b + c)%4] = max(t[(s[j] + b + c)%4], s[j] + b + c);
- }
- }
- s = t;
- t.resize(0);
- t.resize(4);
- }
- cout << s[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement