#include #include #include #include #include #include #include int mmin(int * A,int l,int r){ int ii,min; min=A[l]; for(ii=l;ii<=r;ii++){ if (A[ii]max) max=A[ii]; } return max; } int or(int * A,int l,int r){ int ii,or,jj; or=0; if(l==r) or=A[l]; else{ or=A[l]; for(ii=l+1;ii<=r;ii++){ or=or|A[ii]; } } return or; } int and(int * A,int l,int r){ int ii,and,jj; and=0; if(l==r) and=A[l]; else{ and=A[l]; for(ii=l+1;ii<=r;ii++){ and=and&A[ii]; } } return and; } int* costlyIntervals(int n, int k, int* A, int *result_size) { int *result; int ii,jj,l,r,t_ii,t_jj; int temp_max,max,temp_length,length; *result_size=n; result=(int *) calloc(n,sizeof(int)); // printf("OR %i \n",or(A,0,1)); temp_max=max=temp_length=length=t_ii=t_jj=0; for(ii=0;ii=k){ temp_length=jj-ii+1; if(temp_length>length){ length=temp_length; max=temp_max; t_ii=ii; t_jj=jj; } } } } if (max==0){ for(ii=0;iit_jj) result[ii]=-1; else result[ii]=length; } } // Return a list of length n consisting of the answers return result; } int main() { int n; int k; scanf("%i %i", &n, &k); int *A = malloc(sizeof(int) * n); for (int A_i = 0; A_i < n; A_i++) { scanf("%i",&A[A_i]); } int result_size; int* result = costlyIntervals(n, k, A, &result_size); for(int result_i = 0; result_i < result_size; result_i++) { if(result_i) { printf("\n"); } printf("%d", result[result_i]); } puts(""); return 0; }