fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n; cin >> n;
  6. int x, y; cin >> x >> y;
  7. vector<int> arr(n);
  8. for(int i = 0; i < n; i++)
  9. cin >> arr[i];
  10.  
  11. int area = (x-1)*y; int sum = 0;
  12. for(int i = 0; i <= area; i++){
  13. if(i%y == 0)
  14. sum += arr[i];
  15. }
  16. int ans = sum;
  17. int i = 0; int j = area;
  18. while(j<n){
  19. sum -= arr[i];
  20. i = i+y;
  21. j = j+y;
  22. if(j <= n){
  23. sum += arr[j];
  24. ans = min(sum,ans);
  25. }
  26. }
  27. cout << ans;
  28. return 0;
  29. }
Success #stdin #stdout 0s 5292KB
stdin
10 
4 2
1 2 3 4 5 6 7 8 9 10
stdout
16