链接
题目描述
有 n n n件衣服,第 i i i件衣服的湿度为 h i h_i hi。
在自然条件下,每件衣服每分钟都可以自然晒干 a a a点湿度。
在烘干机作用下,可以选择一件衣服,用一分钟的时间晒干 点 b b b湿度。
求出晒干所有衣服的最少时间(湿度为 0 0 0为干)。
样例输入
3 2 1
1
2
3
样例输出
1
思路
看了样例才知道,自然条件和烘干机是可以同时使用的
最少时间,意味着求得就是最后一件衣服烘干的时间
不考虑烘干机的话,我们所需要的时间就是 h m a x − t ∗ A < = 0 h_{max} - t * A <= 0 hmax−t∗A<=0的 t t t,那烘干机肯定就是给当前湿度最大的用,那用一个大根堆维护即可
代码
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
int h[500005];
int x, a, n, b, ans;
priority_queue<int> Q;
int main()
{
scanf("%d%d%d", &n, &a, &b);
for(int i = 1; i <= n; ++i)
scanf("%d",&h[i]);
for(int i = 1; i <= n; ++i)
Q.push(h[i]);
while(Q.top() - ans * a > 0)
{
ans++;
int tot = Q.top();
Q.pop();
Q.push(tot - b);
}
printf("%d", ans);
return 0;
}