CodeForces - 1296D 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 bhp.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 0The fight with a monster happens in turns. You hit the monster by ahp. 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 ktimes 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,band 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 nintegersh1,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.

Input

6 2 3 3
7 10 50 12 1 8

Output

5

二、思路

  • 每回合掉的血是 a +b, 那么将剩下的值从小到大进行排序,然后判断从头开始枚举,若需要用科技就用,知道不能用为止。

三、代码

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 2e5 + 5;
int n, a, b, k, p[N];
int main() {
	scanf("%d%d%d%d", &n, &a, &b, &k);
	int sum = a + b; 
	for (int i = 1; i <= n; i++) {
		scanf("%d", &p[i]);
		if (p[i] % sum == 0) p[i] = sum;
		else p[i] %= sum;
		p[i] -= a; //每次a先上 
	}
	int ans = 0;
	sort(p + 1, p + 1 + n);
	for (int i = 1; i <= n; i++) {
		if (p[i] <= 0) ans++;
		else {
			int t = ceil(p[i] * 1.0 / a);
			if (t <= k) k-= t, ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
} 
发布了456 篇原创文章 · 获赞 466 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_41280600/article/details/104373993