_takumi

num27.7

Jun 17th, 2021
579
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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\\inf_22_10_20_27b (3).txt");
  10.     long long int n = 0, a = 0, b = 0, s = 0,
  11.         mindiff1 = INT_MAX, mindiff2 = INT_MAX, mindiff12 = INT_MAX, mindiff22 = INT_MAX;
  12.     input >> n;
  13.     for (size_t i = 0; i < n; i++) {
  14.         input >> a >> b;
  15.         if (a < b) swap(a, b);
  16.         s += a;
  17.         if ((a - b) % 3 == 1 && a - b < mindiff1) {
  18.             mindiff12 = mindiff1;
  19.             mindiff1 = a - b;
  20.         }
  21.         else if ((a - b) % 3 == 1 && a - b < mindiff12) {
  22.             mindiff12 = a - b;
  23.         }
  24.         if ((a - b) % 3 == 2 && a - b < mindiff2) {
  25.             mindiff22 = mindiff2;
  26.             mindiff2 = a - b;
  27.         }
  28.         else if ((a - b) % 3 == 2 && a - b < mindiff22) {
  29.             mindiff22 = a - b;
  30.         }
  31.     }
  32.     if (s % 3 == 1) {
  33.         s -= min(mindiff2 + mindiff22, mindiff1);
  34.     }
  35.     else if (s % 3 == 2) {
  36.         s -= min(mindiff1 + mindiff12, mindiff2);
  37.     }
  38.     cout << s;
  39. }
  40. //number 27765
RAW Paste Data