fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MAXN 1000000
  4. int main() {
  5. int n, d;
  6. cin >>n>> d;
  7. int A[MAXN];
  8. for(int i=0; i< n; i++ ){
  9. cin>>A[i];
  10. }
  11. int sum=0;
  12. for(int i=0; i< n; i++ ){
  13. int count=0;
  14. if(A[i]==1){
  15. for(int j=i+d; j<n; j=j+d){
  16. if(A[j]==0) count++;
  17. }
  18. }
  19. sum= max(sum, count);
  20. if(A[i]==0&&A[i+d]==0) break;
  21. }
  22. cout<<sum;
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5500KB
stdin
9 2

1 0 1 0 0 1 0 0 1
stdout
2