Advertisement
Salvens

Untitled

Sep 17th, 2023
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. //#include <ext/pb_ds/assoc_container.hpp>
  4. //using namespace __gnu_pbds;
  5.  
  6. using namespace std;
  7.  
  8. #define int long long
  9. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  10.  
  11. const long long INF = 1e18 + 7;
  12. const double EPS = 1e-6;
  13. const int MAXN = 1e5 + 100;
  14. const int MOD = 1e9 + 7;
  15.  
  16. vector<int> a;
  17. int n, k;
  18.  
  19. bool check(int x) {
  20.     multiset<int> st;
  21.     for (int i = 0; i < k; ++i) {
  22.         st.insert(a[i]);
  23.     }
  24.     for (int i = 0; i + k < n; ++i) {
  25.         st.insert(a[i + k]);
  26.         if (st.lower_bound(x) == st.end()) {
  27.             return false;
  28.         }
  29.         st.erase(st.find(a[i]));
  30.     }
  31.     return true;
  32. }
  33.  
  34. inline void solve() {
  35.     cin >> n >> k;
  36.     a.resize(n);
  37.     for (int i = 0; i < n; ++i) {
  38.         cin >> a[i];
  39.     }
  40.  
  41.     int l = 0, r = 1e5 + 1;
  42.     while (r - l > 1) {
  43.         int mid = (r + l) / 2;
  44.         if (check(mid)) {
  45.             l = mid;
  46.         } else {
  47.             r = mid;
  48.         }
  49.     }
  50.     cout << l << '\n';
  51. }
  52.  
  53.  
  54.  
  55. int32_t main() {
  56.     IOS;
  57.  
  58.     int tt = 1;
  59. //    cin >> tt;
  60.     while (tt--) {
  61.         solve();
  62.     }
  63.     return 0;
  64. }
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement