Josif_tepe

Untitled

Feb 26th, 2026
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <stack>
  5. using namespace std;
  6. typedef long long ll;
  7. const int maxn = 1e5 + 10;
  8. int pref_1[maxn], pref_2[maxn], pref_3[maxn];
  9.  
  10. int main() {
  11.    
  12.     ios_base::sync_with_stdio(false);
  13.     int n;
  14.     cin >> n;
  15.    
  16.     vector<int> v(n);
  17.     vector<int> idx(n, -1);
  18.     int sum = 0;
  19.     int res = 0;
  20.     for(int i = 0; i < n; i++) {
  21.         cin >> v[i];
  22.        
  23.         sum += v[i];
  24.         sum %= 7;
  25.        
  26.         if(idx[sum] == -1) {
  27.             idx[sum] = i;
  28.         }
  29.         else {
  30.             res = max(res, i - idx[sum]);
  31.         }
  32.        
  33.     }
  34.     cout << res << endl;
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment