Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n, k;
- cin >> n >> k;
- int niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- if(niza[i] == 0) {
- niza[i] = 1;
- }
- else {
- niza[i] = 0;
- }
- }
- int j = 0, sum = 0;
- int res = 0, indeks = 0;
- for(int i = 0; i < n; i++) {
- while(j < n and sum + niza[j] <= k) {
- sum += niza[j];
- j++;
- }
- if(res < j - i) {
- res = j - i;
- indeks = i;
- }
- sum -= niza[i];
- }
- cout << res << endl;
- for(int i = indeks; i < indeks + res; i++) {
- if(niza[i] == 1) {
- cout << i + 1 << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement