Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[200005];
- int pref_sum[200005];
- int sum(int i, int j) {
- if(i == 0) {
- return pref_sum[j];
- }
- return pref_sum[j] - pref_sum[i - 1];
- }
- int main() {
- int n, k;
- cin >> n >> k;
- int s = 0;
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- a[i] = 1 - a[i];
- s += a[i];
- pref_sum[i] = s;
- }
- int ret = 0, si, ei;
- for(int i = 0; i < n; i++) {
- int L = i + 1;
- int R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(sum(i, middle) <= k) {
- if(ret < middle - i + 1) {
- ret = middle - i + 1;
- si = i;
- ei = middle;
- }
- L = middle + 1;
- }
- else {
- R = middle - 1;
- }
- }
- }
- cout << ret << endl;
- for(int i = si; i <= ei; i++) {
- if(a[i] == 1) {
- cout << i + 1 << " ";
- }
- }
- return 0;
- }
- // 1 2 3 4 5
- // a --> b imame tocno b - a + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement