Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#include <ext/pb_ds/assoc_container.hpp>
- //using namespace __gnu_pbds;
- using namespace std;
- #define int long long
- #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- const long long INF = 1e18 + 7;
- const double EPS = 1e-6;
- const int MAXN = 1e5 + 100;
- const int MOD = 1e9 + 7;
- vector<int> a;
- int n, k;
- bool check(int x) {
- multiset<int> st;
- for (int i = 0; i < k; ++i) {
- st.insert(a[i]);
- }
- for (int i = 0; i + k < n; ++i) {
- st.insert(a[i + k]);
- if (st.lower_bound(x) == st.end()) {
- return false;
- }
- st.erase(st.find(a[i]));
- }
- return true;
- }
- inline void solve() {
- cin >> n >> k;
- a.resize(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- int l = 0, r = 1e5 + 1;
- while (r - l > 1) {
- int mid = (r + l) / 2;
- if (check(mid)) {
- l = mid;
- } else {
- r = mid;
- }
- }
- cout << l << '\n';
- }
- int32_t main() {
- IOS;
- int tt = 1;
- // cin >> tt;
- while (tt--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement