Fight with Monsters CodeForces - 1296D

There are nn monsters standing in a row numbered from 11 to nn. The ii-th monster has hihi health points (hp). You have your attack power equal to aa hp and your opponent has his attack power equal to bb hp.

You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to 00.

The fight with a monster happens in turns.

You hit the monster by aa hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.
Your opponent hits the monster by bb hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster.
You have some secret technique to force your opponent to skip his turn. You can use this technique at most kk times in total (for example, if there are two monsters and k=4k=4, then you can use the technique 22 times on the first monster and 11 time on the second monster, but not 22 times on the first monster and 33 times on the second monster).

Your task is to determine the maximum number of points you can gain if you use the secret technique optimally.

Input
The first line of the input contains four integers n,a,bn,a,b and kk (1≤n≤2⋅105,1≤a,b,k≤1091≤n≤2⋅105,1≤a,b,k≤109) — the number of monsters, your attack power, the opponent’s attack power and the number of times you can use the secret technique.

The second line of the input contains nn integers h1,h2,…,hnh1,h2,…,hn (1≤hi≤1091≤hi≤109), where hihi is the health points of the ii-th monster.

Output
Print one integer — the maximum number of points you can gain if you use the secret technique optimally.

Examples
Input
6 2 3 3
7 10 50 12 1 8
Output
5
Input
1 1 100 99
100
Output
1
Input
7 4 2 1
1 3 5 4 2 7 6
Output
6
思路:对于每一个h[i],我们都能计算出最小的操作数使得这一分是被自己得到的。我们把所有的值求出来,然后排序之后,看看这个k能满足多少。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=2e5+100;
int c[maxx];
int n,a,b,k,x;

int main()
{
	cin>>n>>a>>b>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x<=a) c[i]=0;
		else if(a<x&&a+b<=x)
		{
			int y=x%(a+b);
			if(y>a) c[i]=y/a-(y%a==0?1:0);
			else if(y==0)
			{
				y=b;
				c[i]=y/a-(y%a==0?1:0)+1;
			}
			else c[i]=0;
		}
		else if(a<x) c[i]=x/a-(x%a==0?1:0);
	}
	//for(int i=1;i<=n;i++) cout<<c[i]<<" ";cout<<endl;
	sort(c+1,c+1+n);c[0]=0;int ans=-1;
	for(int i=1;i<=n;i++)
	{
		c[i]+=c[i-1];
		if(c[i]>k)
		{
			ans=i-1;
			break;
		}
	}
	if(ans!=-1) cout<<ans<<endl;
	else cout<<n<<endl;
	return 0;
}

努力加油a啊,(o)/~

发布了426 篇原创文章 · 获赞 24 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/starlet_kiss/article/details/104279952