fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. void solve(){
  7. int n,x,y;
  8. cin>>n>>x>>y;
  9. vector<int>v(n);
  10. for(int &i:v)cin>>i;
  11.  
  12. // 0 1 2 3
  13. // 4 2 3 7
  14.  
  15. vector<int>pref(n+1,0);
  16. for(int i=0;i<n;i++){
  17. if(i-y>=0)pref[i+1]=pref[i-y+1]+v[i];
  18. else pref[i+1]=v[i];
  19. }
  20.  
  21. // y=2, x=2
  22. // 0 1 2 3 4
  23. // 0 4 2 7 9
  24.  
  25. ll k = 1e18 ;
  26. for(ll i=1;i<=n;i++){
  27.  
  28. ll index = i - (x-1)*y;
  29. if(index>=1){
  30. ll g = pref[i] ;
  31. if(index-y>=1){
  32. g = g - pref[index-y] ;
  33. }
  34. k = min(g,k);
  35. cout<<g ;
  36. cout<<'\n';
  37. }
  38. }
  39. cout<<k<<"\n";
  40. }
  41.  
  42. int main(){
  43. ios_base::sync_with_stdio(false);
  44. cin.tie(NULL);
  45. solve();
  46. return 0;
  47. }
Success #stdin #stdout 0s 5324KB
stdin
4 2 2
4 2 3 7
stdout
7
9
7