Fight with Monsters

There are n monsters standing in a row numbered from 1 to n. The i-th monster has hi health points (hp). You have your attack power equal to a hp and your opponent has his attack power equal to b 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 0.

The fight with a monster happens in turns.

You hit the monster by a 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 b 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 k times in total (for example, if there are two monsters and k=4, then you can use the technique 2 times on the first monster and 1 time on the second monster, but not 2 times on the first monster and 3 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,b and k (1≤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 n integers h1,h2,…,hn (1≤hi≤109), where hi is the health points of the i-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
题意:有n个怪兽,两个人一起打怪兽,第一个人的伤害是a,第二个人的伤害是b,若是怪兽的血量在第一个人打完之后血量小于等于0,则这个人得分,否则不得分,但是第一个人有k次让第二个人不攻击的技能,问第一个人到最后能得几分。
思路:每个怪兽的血量先对两个人攻击伤害的和进行取余,若余数为零且第一个人不使用技能的话,则说明这个怪兽会在第二个人打完之后死亡,那么就让这个怪兽的血量为b。而余数不为零则让怪兽的血量为余数且减去a血量记为该怪兽的血量,这样操作完成之后,所有的怪兽都该等着第二个人的攻击,这时候进行排序然后判断,若是怪兽血量为负数或是0,则说明该怪兽被第一个人打死,并且得分,接着考虑几种情况就OK。

#include"cstdio"
#include"cstring"
#include"algorithm"
#define Maxn 200005
using namespace std;
int x[Maxn];
int main()
{
	int n,a,b,k;
	while(~scanf("%d %d %d %d",&n,&a,&b,&k))
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d",&x[i]);
			x[i]=x[i]%(a+b);
		}
		for(int i=0;i<n;i++)
		{
			if(x[i]==0)
			{
				x[i]=b;
			}
			else
			{
				x[i]-=a;
			}
		}
		sort(x,x+n);
		int num=0;
		for(int i=0;i<n;i++)
		{
			if(x[i]<=0)
			{
				num++;
			}
			else
			{
				if(a*k<x[i])
				{
					break;
				}
				else if(a*k==x[i])
				{
					num++;
					break;
				}
				else
				{
					int m=0,l=0;
					m=x[i]/a;
					l=x[i]%a;
					if(l==0)
					{
						k-=m;
						num++;
					}
					else
					{
						k=k-m-1;
						num++;
					}
				}
			}
		}
		printf("%d\n",num);
	}
	return 0;
}
发布了76 篇原创文章 · 获赞 1 · 访问量 2761

猜你喜欢

转载自blog.csdn.net/weixin_44824383/article/details/104918957