QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#867801 | #9423. Gold Medal | Sxuanyan | WA | 1ms | 3584kb | C++23 | 2.3kb | 2025-01-24 00:52:09 | 2025-01-24 00:52:10 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
// 定义一个结构体来存储比赛的信息
struct Contest {
long long current; // 当前参与人数
long long increment; // 增量(每多分配一个队员带来的金牌增量)
int index; // 比赛索引(便于更新)
// 定义优先队列的比较规则(按增量降序)
bool operator<(const Contest& other) const {
return increment < other.increment;
}
};
// 计算分配 x 个队员后金牌数
long long calculateGold(long long participants, long long k) {
return participants / k;
}
// 计算分配一个队员后的金牌增量
long long calculateIncrement(long long current, long long k) {
return calculateGold(current + 1, k) - calculateGold(current, k);
}
int main() {
int T; // 测试用例数
cin >> T;
while (T--) {
int n; // 比赛数量
long long k; // 金牌分配比例
cin >> n >> k;
vector<long long> participants(n); // 当前参与人数
for (int i = 0; i < n; i++) {
cin >> participants[i];
}
long long m; // 可分配的队员数
cin >> m;
// 优先队列,按增量降序排列
priority_queue<Contest> pq;
// 初始化优先队列
for (int i = 0; i < n; i++) {
long long increment = calculateIncrement(participants[i], k);
pq.push({participants[i], increment, i});
}
// 分配队员
while (m--) {
// 取出当前增量最大的比赛
Contest top = pq.top();
pq.pop();
// 更新比赛的参与人数
participants[top.index]++;
// 重新计算增量
long long newIncrement = calculateIncrement(participants[top.index], k);
// 将更新后的比赛重新放回优先队列
pq.push({participants[top.index], newIncrement, top.index});
}
// 计算总金牌数
long long totalGold = 0;
for (int i = 0; i < n; i++) {
totalGold += calculateGold(participants[i], k);
}
// 输出结果
cout << totalGold << endl;
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
input:
2 3 10 239 141 526 6 2 1 300 100 1000
output:
90 1400
result:
wrong answer 1st lines differ - expected: '91', found: '90'