#include<iostream> usingnamespace std; constint N = 2e5 + 10; int n, k; int a[N]; int b[N]; // 标记数组 int pre[N]; // 记录前i个前缀和 int mn[N]; // 记录前i个最小的前缀和 voidinit(){for (int i = 1; i <= n; i++) b[i] = pre[i] = 0, mn[i] = 0x3f3f3f3f;} boolcheck(int x){ init(); for (int i = 1; i <= n; i++) { if (a[i] >= x) b[i] = 1; else b[i] = -1; } for (int i = 1; i <= n; i++) pre[i] = pre[i-1] + b[i]; for (int i = 1; i <= n; i++) mn[i] = min(mn[i-1], pre[i]); for (int i = k; i <= n; i++) { // 枚举右端点 int sum = pre[i] - mn[i-k]; // 贪心思想 if (sum > 0) returntrue; } returnfalse; } intmain(){ cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 1, r = n, mid; while (l < r) { mid = (l+r+1) >> 1; if (check(mid)) { l = mid; } else { r = mid - 1; } } cout << l << endl; return0; }