Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- int main() {//00:25
- ifstream f("C:/inp/st170321/27/27-B.txt");
- int n;
- f >> n;
- long zero[3] = { 0 };
- int z = 0;
- long one[3] = { 0 };
- int o = 0;
- long two[3] = { 0 };
- int t = 0;
- long a;
- for (int i = 0; i < n; i++) {
- f >> a;
- if (a % 3 == 0) {
- if (a > zero[z]) {
- z++;
- if (z > 2) z = 0;
- zero[z] = a;
- }
- }
- else if (a % 3 == 1) {
- if (a > one[o]) {
- o++;
- if (o > 2) o = 0;
- one[o] = a;
- }
- }
- else {
- if (a > two[t]) {
- t++;
- if (t > 2) t = 0;
- two[t] = a;
- }
- }
- }
- long maxx = 0;
- //Как получить остаток 3:
- //0 + 0 + 0
- //1 + 1 + 1
- //2 + 2 + 2
- //0 + 1 + 2
- //а хотя можно просто перебрать все 27 вариантов + сумму каждого массива
- if ((zero[0] + zero[1] + zero[2]) > maxx)
- maxx = zero[0] + zero[1] + zero[2];
- if ((one[0] + one[1] + one[2]) > maxx)
- maxx = one[0] + one[1] + one[2];
- if ((two[0] + two[1] + two[2]) > maxx)
- maxx = two[0] + two[1] + two[2];
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- for (int k = 0; k < 3; k++) {
- if ((zero[i] + one[j] + two[k]) > maxx)
- maxx = zero[i] + one[j] + two[k];
- }
- }
- }
- cout << maxx << endl; //00:40
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement