Advertisement
Pearlfromsu

sst170321_27

Mar 26th, 2021
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {//00:25
  8.     ifstream f("C:/inp/st170321/27/27-B.txt");
  9.     int n;
  10.     f >> n;
  11.     long zero[3] = { 0 };
  12.     int z = 0;
  13.     long one[3] = { 0 };
  14.     int o = 0;
  15.     long two[3] = { 0 };
  16.     int t = 0;
  17.  
  18.     long a;
  19.     for (int i = 0; i < n; i++) {
  20.         f >> a;
  21.         if (a % 3 == 0) {
  22.             if (a > zero[z]) {
  23.                 z++;
  24.                 if (z > 2) z = 0;
  25.                 zero[z] = a;
  26.             }
  27.         }
  28.         else if (a % 3 == 1) {
  29.             if (a > one[o]) {
  30.                 o++;
  31.                 if (o > 2) o = 0;
  32.                 one[o] = a;
  33.             }
  34.         }
  35.         else {
  36.             if (a > two[t]) {
  37.                 t++;
  38.                 if (t > 2) t = 0;
  39.                 two[t] = a;
  40.             }
  41.         }
  42.     }
  43.  
  44.     long maxx = 0;
  45.  
  46.     //Как получить остаток 3:
  47.     //0 + 0 + 0
  48.     //1 + 1 + 1
  49.     //2 + 2 + 2
  50.     //0 + 1 + 2
  51.     //а хотя можно просто перебрать все 27 вариантов + сумму каждого массива
  52.  
  53.     if ((zero[0] + zero[1] + zero[2]) > maxx)
  54.         maxx = zero[0] + zero[1] + zero[2];
  55.     if ((one[0] + one[1] + one[2]) > maxx)
  56.         maxx = one[0] + one[1] + one[2];
  57.     if ((two[0] + two[1] + two[2]) > maxx)
  58.         maxx = two[0] + two[1] + two[2];
  59.  
  60.     for (int i = 0; i < 3; i++) {
  61.         for (int j = 0; j < 3; j++) {
  62.             for (int k = 0; k < 3; k++) {
  63.                 if ((zero[i] + one[j] + two[k]) > maxx)
  64.                     maxx = zero[i] + one[j] + two[k];
  65.             }
  66.         }
  67.     }
  68.     cout << maxx << endl; //00:40
  69.  
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement