55010 - [CSP-J2020]直播获奖(live)

解题思路

直接桶排序。

参考代码

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	//freopen("live.in", "r", stdin);
 	//freopen("live.out", "w", stdout);
 	int n, w, a[100000], cnt[601] = {0};
 	cin >> n >> w;
 	for (int i = 0; i < n; i++) {
 		scanf("%d", &a[i]);
 		cnt[a[i]]++;
 		int x = (i + 1) * w / 100;
 		if (!x) x = 1;
 		for (int j = 600, s = 0; j >= 0; j--) {
 			s += cnt[j];
 			if (s >= x) {
 				cout << j << " ";
 				break;
 			}
 		}
 	}
 	return 0;
}