Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.1 kB
1
Indexable
Never
#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
int n, k;
int a[maxn];
int pref_sum[maxn];
int s(int i, int j) {
    if(i == 0) {
        return pref_sum[j];
    }
    return pref_sum[j] - pref_sum[i - 1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    int sum = 0, ret = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += (1 - a[i]);
        pref_sum[i] = sum;
    }
    int L, R, mid;
    int si, sj;
    for(int i = 0; i < n; i++) {
        L = i + 1;
        R = n - 1;
        while(L <= R) {
            mid = (L + R) / 2;
            if(s(i, mid) <= k) {
                if(mid - i + 1 > ret) {
                    ret = mid - i + 1;
                    si = i;
                    sj = mid;
                }
                L = mid + 1;
            }
            else {
                R = mid - 1;
            }
        }
    }
    cout << ret << endl;
    for(int i = si; i <= sj; i++) {
        if(a[i] == 0) {
            cout << i + 1 << " ";
        }
    }
    return 0;
}