Advertisement
AquaBlitz11

L-Sequence

Apr 4th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <cstdio>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, k;
  9.     scanf("%d%d", &n, &k);
  10.     list<int> num;
  11.     for (int i = 0; i < n; ++i) {
  12.         int x;
  13.         scanf("%d", &x);
  14.         num.push_back(x);
  15.     }
  16.  
  17.     while (k--) {
  18.         bool rem = false;
  19.         for (auto it = num.begin(); it != prev(num.end()); ++it) {
  20.             if (*it > *next(it)) {
  21.                 num.erase(it);
  22.                 rem = true;
  23.                 break;
  24.             }
  25.         }
  26.         if (!rem)
  27.             num.pop_back();
  28.     }
  29.  
  30.     for (auto x : num)
  31.         printf(" %d", x);
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement