Advertisement
Ankit_132

B

Feb 27th, 2024
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int t;
  6.     cin>>t;
  7.    
  8.     while(t--){
  9.         int n;
  10.         cin>>n;
  11.        
  12.         vector<int> a(n);
  13.         for(auto &e: a)     cin>>e;
  14.        
  15.         int tot = accumulate(a.begin(), a.end(), 0);
  16.        
  17.         int ans = (3 - tot%3)%3;
  18.        
  19.         int one=0, two=0;
  20.        
  21.         for(auto e: a)
  22.         {
  23.             one += (e%3 == 1);
  24.             two += (e%3 == 2);
  25.         }
  26.        
  27.         if(tot%3==1 && one)      ans = min(ans, 1);
  28.         if(tot%3==2 && two)      ans = min(ans, 1);
  29.        
  30.         cout<<ans<<"\n";
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement