Advertisement
shawon_majid

usaco subsequence summing to seven

May 20th, 2021
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. //Bismillahir Rahman-ir Rahim
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define debug(x) cout << '>' << #x << " : " << x << endl;
  5. #define all(c) c.begin(), c.end()
  6. #define F first
  7. #define S second
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10.  
  11.  
  12. int main(){
  13.  
  14.     //freopen("input.txt", "r", stdin);
  15.     //freopen("output.txt", "w", stdout);
  16.  
  17.     long long int n;
  18.     cin >> n;
  19.     vector <long long> ara(n), pre(n);
  20.     for(int i = 0;i < n; i++){
  21.         cin >> ara[i];
  22.     }
  23.     pre[0] = ara[0];
  24.     for(int i = 1; i < n; i++){
  25.         pre[i] = pre[i-1] + ara[i];
  26.     }
  27.     ll ans = 0, sum = 0;
  28.     for(int i = 0; i < n; i++){
  29.         for(int j = i; j < n; j++){
  30.             if(i!=0)sum = pre[j] - pre[i-1];
  31.             else sum = pre[j];
  32.             if(sum % 7 == 0){
  33.                 ans = max(ans, (ll)(j-i+1));
  34.             }
  35.         }
  36.     }
  37.     cout << ans << endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement