Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- int niza[n];
- int pref_sums[n];
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- if(niza[i] == 0) {
- sum += 1;
- }
- pref_sums[i] = sum;
- }
- int res = 0, S = 0;
- for(int i = 0; i < n; i++) {
- int L = i + 1;
- int R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(i == 0) {
- sum = pref_sums[middle];
- }
- else {
- sum = pref_sums[middle] - pref_sums[i - 1];
- }
- if(sum <= m) {
- if(res < middle - i + 1) {
- res = middle - i + 1;
- S = i;
- }
- L = middle + 1;
- }
- else {
- R = middle - 1;
- }
- }
- }
- cout << res << endl;
- for(int i = S; i < S + res; i++) {
- if(niza[i] == 0) {
- cout << i + 1 << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement