Advertisement
Josif_tepe

Untitled

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