[ AGC006 D ] Median Pyramid Hard

题目

Atcoder

思路

006D01.png 006D02.png

代码

#include <iostream>
using namespace std;
const int N = 200010;
int n, m, a[N], b[N];
int check(int mid) {
    for (int i = 1; i <= n * 2 - 1; i++) 
        b[i] = a[i] >= mid;
    int p = 2e9, res = b[1];
    for (int i = n; i <= 2 * n - 1; i++) 
        if (b[i] == b[i + 1] && i - n < p) p = i - n, res = b[i];
    for (int i = n; i >= 1; i--)
        if (b[i] == b[i - 1] && n - i < p) p = n - i, res = b[i];
    return res;
}
int main() {
    cin >> n;
    for (int i = 1; i <= n * 2 - 1; i++) cin >> a[i];
    int l = 1, r = 2 * n - 1;
    while (l < r) {
        int mid = (l + r + 1) >> 1;
        if (check(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l << endl;
    return 0;
}
posted @ 2021-05-29 12:31  Protein_lzl  阅读(66)  评论(0编辑  收藏  举报