Advertisement
Josif_tepe

Untitled

May 12th, 2024
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n, k;
  6.     cin >> n >> k;
  7.  
  8.     int niza[n];
  9.     for(int i = 0; i < n; i++) {
  10.         cin >> niza[i];
  11.  
  12.         if(niza[i] == 0) {
  13.             niza[i] = 1;
  14.         }
  15.         else {
  16.             niza[i] = 0;
  17.         }
  18.     }
  19.  
  20.     int j = 0, sum = 0;
  21.     int res = 0, indeks = 0;
  22.     for(int i = 0; i < n; i++) {
  23.         while(j < n and sum + niza[j] <= k) {
  24.             sum += niza[j];
  25.             j++;
  26.         }
  27.         if(res < j - i) {
  28.             res = j - i;
  29.             indeks = i;
  30.         }
  31.         sum -= niza[i];
  32.     }
  33.     cout << res << endl;
  34.     for(int i = indeks; i < indeks + res; i++) {
  35.         if(niza[i] == 1) {
  36.             cout << i + 1 << " ";
  37.         }
  38.     }
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement