[YBT high-efficiency advanced] 1 basic algorithm/2 greedy algorithm/1 cow drying clothes&【Luogu】P1843 cow drying clothes

[YBT high-efficiency advanced] 1 basic algorithm/2 greedy algorithm/1 cow drying clothes&【Luogu】P1843 cow drying clothes

Topic background

Aunt Xiong decided to put cute baby clothes on every baby cow. But because the clothes are very wet, drying clothes for the baby cow becomes very uncomfortable. So, Aunt Xiong asked you (the cow) to help her complete this important task.

Title description

A piece of clothing can be dried at a point of humidity in one second under natural conditions. The stingy Aunt Xiong only bought a dryer. Using a one-second dryer can make a piece of clothing dry at b point humidity (one second to dry a + b humidity), but only one piece of clothing can be dried at the same time. There are n pieces of clothing, the humidity of the clothes for i W i (guaranteed different from each other), to determine the minimum time you all the clothes drying (humidity 0 dry).

Input format

The three integers in the first line are n, a, b.
In the next 2 to n+1 lines, enter w i on the i-th line .

Output format

One line, the minimum time to dry all the clothes.

Sample input and output

enter
3 2 1
1
2
3
Output
1

Instructions/tips

Sample explanation
Let the machine bake the third garment in one second.

Data range
1 ≤ wi, a, b, n ≤ 5 × 1 0 5 1 \le w_i,a,b,n \le 5 \times 10^51wi,a,b,n5×105

Ideas

Use the dryer to dry the clothes with the highest humidity every minute.
Use heap optimization.

Code

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
priority_queue<int> q;//堆优化 
int main()
{
    
    
	int n,a,b,t=0,ans,tem;
	for(scanf("%d%d%d",&n,&a,&b);n;n--)
		scanf("%d",&tem),q.push(tem);
	for(ans=0;q.top()>t;ans++)
	{
    
    
		tem=q.top();
		q.pop();//出堆 
		q.push(tem-b);//入堆 
		t+=a;
	}
	printf("%d\n",ans);
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_46975572/article/details/113032709
Recommended