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