WA 了一个点,求调 /ll
查看原帖
WA 了一个点,求调 /ll
693428
unDefined_Future楼主2024/10/21 10:56

WA 了 subtask 3 第 4 个点。真的调不出来了

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int M = 2000010;
int n, m, a[M];

bool chk(int mid) {
    int cnt = 0, lx = 0;
    for (int i = 1; i <= n; i++) {
        if(a[i] < mid) lx++;
        else if(lx) cnt = max(cnt, lx == i - 1 ? lx : max(lx - 1, 1ll)), lx = 0;
    }
    cnt = max(cnt, lx);
    return cnt <= m;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if(n == 1) return cout << a[1], 0;
    int maxx = 0;
    for (int i = 1; i <= n; i++) maxx = max(maxx, a[i]);
    int l = 1, r = maxx;
    while(l < r) {
        int mid = (l + r + 1) / 2;
        if(chk(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l;
    return 0;
}
2024/10/21 10:56
加载中...