Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int pref_sum[200002];
- int suma(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 niza[n];
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- if(niza[i] == 0) {
- sum += 1;
- }
- pref_sum[i] = sum;
- }
- int res = 0, indeks = 0;
- for(int i = 0; i < n; i++) {
- int L = i + 1, R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(suma(i, middle) <= k) {
- if(res < middle - i + 1) {
- res = middle - i + 1;
- indeks = i;
- }
- L = middle + 1;
- }
- else {
- R = middle - 1;
- }
- }
- }
- cout << res << endl;
- for(int i = indeks; i < indeks + res; i++) {
- if(niza[i] == 0) {
- cout << i + 1 << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement