题目背景
熊大妈决定给每个牛宝宝都穿上可爱的婴儿装 。 于是 , 为牛宝宝洗晒衣服就成了很不爽的事情。
题目描述
熊大妈请你帮助完成这个重任 。 洗完衣服后 , 你就要弄干衣服 。 衣服在自然条件下用1的时间可以晒干A点湿度 。 抠门的熊大妈买了1台烘衣机 。使用烘衣机可以让你用1的时间使1件衣服除了自然晒干
输入格式
第一行N,
接下来
输出格式
一行,弄干所有衣服的最少时间。
输入样例#1
3 2 1
1
2
3
输出样例#1
1
说明
第1个时间内,用机器处理第3件衣服,此外,所有衣服自然晒干。花费1时间全部弄干。
思路
贪心思想,每一个时刻机器处理最湿的那件衣服,排序就用堆吧。自然干燥的话,记录add值,每次操作都加一次add值,如果最高的衣服的干燥度小于等于add,说明已经所有衣服都完全干燥了。
代码
#include <cstdio>
#include <algorithm>
const int maxn=500000;
int n,a,b,add,ans;
struct heap
{
int h[maxn+10],tot;
int push(int a)
{
tot++;
h[tot]=a;
int now=tot;
while((now>1)&&(h[now>>1]<h[now]))
{
std::swap(h[now>>1],h[now]);
now>>=1;
}
return 0;
}
int top()
{
return h[1];
}
int pop()
{
h[1]=h[tot];
tot--;
int now=1;
while(((now<<1<n)&&(h[now]<std::max(h[now<<1],h[now<<1|1])))||((now<<1==n)&&(h[now]<h[now<<1])))
{
if((now<<1==n)||(h[now<<1]>h[now<<1|1]))
{
std::swap(h[now],h[now<<1]);
now<<=1;
}
else
{
std::swap(h[now],h[now<<1|1]);
now=now<<1|1;
}
}
return 0;
}
};
heap t;
int main()
{
scanf("%d%d%d",&n,&a,&b);
for(int i=1; i<=n; i++)
{
int c;
scanf("%d",&c);
t.push(c);
}
while(t.top()>add)
{
ans++;
int to=t.top();
t.pop();
t.push(to-b);//对这件衣服用机器烘干
add+=a;//每件衣服都自然干燥
}
printf("%d\n",ans);
return 0;
}