Advertisement
cosenza987

this shit aint working

Aug 16th, 2021
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. // Problem: B. Hometask
  2. // Contest: Codeforces - Codeforces Round #131 (Div. 2)
  3. // Memory Limit: 256 MB
  4. // Time Limit: 2000 ms
  5. // Date / Time: 2021-08-16 09:24:28
  6. // Author: cosenza
  7. // всё что ни делается - всё к лучшему
  8. // check list -> long long, special cases, array size, mod (a*b%p*c%p not a*b*c%p  ,  (a-b+p)%p not a-b )
  9. //
  10. // Powered by CP Editor (https://cpeditor.org)
  11.  
  12. #include <bits/stdc++.h>
  13.  
  14. using namespace std;
  15.  
  16. int main() {
  17.     ios_base::sync_with_stdio(false);
  18.     cin.tie(0);
  19.     int n;
  20.     cin >> n;
  21.     multiset<int> ms;
  22.     int cnt0 = 0, r1 = 0, r2 = 0;
  23.     for(int i = 0; i < n; i++) {
  24.         int k;
  25.         cin >> k;
  26.         ms.insert(k);
  27.         if(k == 0) {
  28.             cnt0++;
  29.         }
  30.         if(k % 3 == 1) {
  31.             r1++;
  32.         } else if(k % 3 == 2) {
  33.             r2++;
  34.         }
  35.     }
  36.     int tot = accumulate(ms.begin(), ms.end(), 0);
  37.     if(!cnt0) {
  38.         cout << "-1\n";
  39.         return 0;
  40.     }
  41.     if(tot % 3 == 1) {
  42.         if(r1) {
  43.             for(auto k : ms) {
  44.                 if(k % 3 == 1) {
  45.                     ms.erase(ms.find(k));
  46.                     break;
  47.                 }
  48.             }
  49.         } else if(r2) {
  50.             int cnt = 0;
  51.             for(auto k : ms) {
  52.                 if(k % 3 == 2 and cnt < 2) {
  53.                     ms.erase(ms.find(k));
  54.                     cnt++;
  55.                 }
  56.                 if(cnt == 2) {
  57.                     break;
  58.                 }
  59.             }
  60.         } else {
  61.             cout << "-1\n";
  62.             return 0;
  63.         }
  64.     } else if(tot % 3 == 2) {
  65.         if(r2) {
  66.             for(auto k : ms) {
  67.                 if(k % 3 == 2) {
  68.                     ms.erase(ms.find(k));
  69.                     break;
  70.                 }
  71.             }
  72.         } else if(r1) {
  73.             int cnt = 0;
  74.             for(auto k : ms) {
  75.                 if(k % 3 == 1 and cnt < 2) {
  76.                     ms.erase(ms.find(k));
  77.                     cnt++;
  78.                 }
  79.                 if(cnt == 2) {
  80.                     break;
  81.                 }
  82.             }
  83.         } else {
  84.             cout << "-1\n";
  85.             return 0;
  86.         }
  87.     }
  88.     vector<int> v(ms.begin(), ms.end());
  89.     reverse(v.begin(), v.end());
  90.     for(auto k : v) {
  91.         cout << k;
  92.     }
  93.     cout << "\n";
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement