_takumi

num27.8

Jun 17th, 2021 (edited)
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ifstream input("C:\\Users\\Максим\\Downloads\\28128_A (4).txt");
  10.     long long int n = 0, now = 0, max1 = 0, max2 = 0, max01 = 0, max02 = 0, s = 0;
  11.     input >> n;
  12.     for (size_t i = 0; i < n; i++)
  13.     {
  14.         input >> now;
  15.         if (now % 3 == 0 && now > max01) {
  16.             if (max01 > max02)
  17.                 max02 = max01;
  18.             max01 = now;
  19.         }
  20.         else if (now % 3 == 0 && now > max02) {
  21.             max02 = now;
  22.         }
  23.         if (now % 3 == 1 && now > max1) {
  24.             max1 = now;
  25.         }
  26.         if (now % 3 == 2 && now > max2) {
  27.             max2 = now;
  28.         }
  29.     }
  30.     cout << max(max01 + max02, max2 + max1);
  31. }
Add Comment
Please, Sign In to add comment