Advertisement
Mahmoud_Hawara

Untitled

Mar 13th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. const long long N = 2e5 + 5, MOD = 1e9 + 7, OO = 1e18;
  5. const double PI = acos(-1);
  6. const int dx[4] = {0, 0, 1, -1};
  7. const int dy[4] = {1, -1, 0, 0};
  8.  
  9. long long t, n, k, a[N];
  10.  
  11. int main() {
  12.     IO
  13.     cin >> t;
  14.     while (t--) {
  15.         cin >> n >> k;
  16.         for (int i = 1; i <= n; i++)cin >> a[i];
  17.         deque<long long>dq;
  18.         map<long long, long long, greater<long long>>mp;
  19.         for (int i = 1; i < k; i++) {
  20.             dq.push_back(a[i]);
  21.             mp[a[i]]++;
  22.         }
  23.         dq.push_front(0LL);
  24.         mp[0LL]++;
  25.         for (int i = k; i <= n; i++) {
  26.             mp[dq.front()]--;
  27.             if (mp[dq.front()] == 0)mp.erase(dq.front());
  28.             dq.pop_front();
  29.             dq.push_back(a[i]);
  30.             mp[a[i]]++;
  31.             cout << mp.begin()->first << ' ';
  32.         }
  33.         cout << '\n';
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement