← 返回题目页

P7072 [CSP-J 2020] 直播获奖

标程

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, w;
    cin >> n >> w;

    const int MAXS = 600;
    int cnt[MAXS + 1] = {0};
    int pos = MAXS;  // 当前分数线候选;sum = 分数 >= pos 的人数
    int sum = 0;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
        if (x >= pos) sum++;

        int k = max(1, i * w / 100);

        while (sum < k) { pos--; sum += cnt[pos]; }
        while (sum - cnt[pos] >= k) { sum -= cnt[pos]; pos++; }

        if (i > 1) cout << ' ';
        cout << pos;
    }
    cout << "\n";
    return 0;
}

动画演示