C11CAVE - Hang động

Tác giả: happyboy99x

Ngôn ngữ: C++

#include<cstdio>
#include<algorithm>
using namespace std;

int c[2][100000], cnt[100001], n, h;

int main() {
    scanf("%d%d",&n,&h);
    for(int i = 0; i < n; ++i) scanf("%d", &c[i%2][i/2]);
    n /= 2; sort(c[0], c[0]+n); sort(c[1], c[1]+n);
    int mn = (int) 1e9; 
    for(int i = 1; i <= h; ++i) {
        int t = n - (upper_bound(c[0], c[0]+n, i-1) - c[0]);
        t += n - (upper_bound(c[1], c[1]+n, h-i) - c[1]);
        ++cnt[t];
        mn = min(mn, t);
    }
    printf("%d %d\n", mn, cnt[mn]);
    return 0;
}

Download