Files
python/GESP/Level5/P1843_TanXin.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

27 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
// https://www.luogu.com.cn/problem/P1843
priority_queue<int> q; // 每次很方便地找到最大值,默认是大顶堆
int n, a, b;
int ans;
int main() {
cin >> n >> a >> b; // 衣服数目,自然晒干,烘干机晒干
for (int i = 1; i <= n; i++) { // 第 i 件衣服的湿度为 w[i]
int w;
cin >> w;
q.push(w);
}
int mx = q.top();
q.pop(); // 每次考虑最湿的衣服就可以了
while (mx > ans * a) { // 如果现在湿度最大的衣服,它在规定时间ans的情况下,自然就可以干了,那就是找到了第一个最小的ans答案
ans++; // 增加1分钟,继续尝试看看是不是可以完成所有衣服的烘干
mx -= b; // 我们默认的贪心策略是挑湿度高的先烘干,所以,烘干机肯定先给湿度最高的衣服使用
q.push(mx);
mx = q.top();
q.pop(); // 重新更新,继续使用
}
cout << ans << endl;
return 0;
}