Advertisement
mickypinata

CUBE-T019: L-Sequence

Jul 19th, 2021
1,346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1000;
  5.  
  6. int arr[N + 1];
  7.  
  8. int main(){
  9.  
  10.     int nNumber, cut;
  11.     scanf("%d%d", &nNumber, &cut);
  12.     for(int i = 1; i <= nNumber; ++i){
  13.         scanf("%d", &arr[i]);
  14.     }
  15.     int len = nNumber - cut;
  16.     int cnt = 0;
  17.     int i = 1;
  18.     while(cnt < len){
  19.         int mn = 1e9;
  20.         int mnIdx = i;
  21.         for(int j = i; j <= i + cut; ++j){
  22.             if(arr[j] < mn){
  23.                 mn = arr[j];
  24.                 mnIdx = j;
  25.             }
  26.         }
  27.         cout << mn << ' ';
  28.         cut -= mnIdx - i;
  29.         i = mnIdx + 1;
  30.         ++cnt;
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement