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++) {
- int lampa;
- cin >> lampa;
- if(lampa == 0) {
- niza[i] = 1;
- }
- else {
- niza[i] = 0;
- }
- }
- int j = 0, sum = 0;
- int najgolema_podniza = 0;
- int pocetok, kraj;
- for(int i = 0; i < n; i++) {
- while(j < n and sum + niza[j] <= k) {
- sum += niza[j];
- j++;
- }
- if(j - i > najgolema_podniza) {
- najgolema_podniza = j - i;
- pocetok = i;
- kraj = j;
- }
- sum -= niza[i];
- }
- cout << najgolema_podniza << endl;
- for(int i = pocetok; i < kraj; i++) {
- if(niza[i] == 1) {
- cout << i + 1 << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement