Ankit_132

B

Nov 17th, 2023
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.  
  13.     int N = 150000 + 1;
  14.  
  15.     vector<vector<int>> div(N);
  16.  
  17.     for(int i=1; i<N; i++)
  18.     {
  19.         for(int j=2*i; j<N; j+=i)
  20.             div[j].pb(i);
  21.     }
  22.  
  23.     _test
  24.     {
  25.         int n;
  26.         cin>>n;
  27.  
  28.         vector<ll int> a(n);
  29.         for(auto &e: a)     cin>>e;
  30.  
  31.         ll int ans = 0;
  32.  
  33.         for(auto d: div[n])
  34.         {
  35.             ll int mmin = 1e18;
  36.             ll int mmax = -1e18;
  37.             ll int s;
  38.  
  39.             for(int i=0; i<n; i+=d)
  40.             {
  41.                 s = accumulate(a.begin()+i, a.begin()+i+d, 0ll);
  42.  
  43.                 mmin = min(mmin, s);
  44.                 mmax = max(mmax, s);
  45.             }
  46.  
  47.             ans = max(ans, mmax-mmin);
  48.         }
  49.  
  50.         cout<<ans<<"\n";
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment