CSP-J2020 Question 2 (Live Broadcast Award) Solution

The problem- solving idea of ​​the problem-
topic portal is the direct bucket sorting. Reference Code


#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;
}

Guess you like

Origin blog.csdn.net/yueyuedog/article/details/112462334