Advertisement
Josif_tepe

Untitled

Mar 24th, 2022
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4. using namespace std;
  5. int cnt_all[6001], cnt_after_last_zero[6000];
  6. int main()
  7. {
  8.     memset(cnt_all, 0, sizeof cnt_all);
  9.     memset(cnt_after_last_zero, 0, sizeof cnt_after_last_zero);
  10.     bool dali = false;
  11.     while(true) {
  12.         int x;
  13.         cin >> x;
  14.         if(x == 11111) break;
  15.         if(x == 0 and dali) {
  16.             memset(cnt_after_last_zero, 0, sizeof cnt_after_last_zero);
  17.         }
  18.         if(x == 0) {
  19.             dali = true;
  20.         }
  21.         if(x != 0 and dali) {
  22.             cnt_all[x]++;
  23.             cnt_after_last_zero[x]++;
  24.         }
  25.     }
  26.     int maks = -1, minn = 6005;
  27.     for(int i = 6000; i >= 600; i--) {
  28.         cnt_all[i] -= cnt_after_last_zero[i];
  29.         if(cnt_all[i] > 0) {
  30.             maks = max(maks, i);
  31.             minn = min(minn, i);
  32.         }
  33.     }
  34.     cout << maks - minn << endl;
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement