CF 617 D. Fight with Monsters

D. 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

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 10;
int n, x, y, k;
int a[maxn];
int b[maxn], c[maxn];
int ans = 0;
int main() {
	cin >> n >> x >> y >> k;
	int xy = x + y;
	int tot = 0, cnt = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i] % xy == 0)
			b[tot++] = a[i];
		else if(a[i] % xy <= x)
			ans++;
		else {
			c[cnt++] = a[i] % xy - x;
		}
	} 
	sort(c, c + cnt);
	int k1 = ceil(double(y) / x);
	for(int i = 0; i < cnt; i++) {
		int k2 = ceil(double(c[i]) / x);
		if(k2 <= k1 && k >= k2) {
			k -= k2;
			ans++;
		}
		else if(tot && k2 >= k1 && k >= k1) {
			tot--;
			ans++;
			k -= k1;
			i--;
		}
	}
	while(tot) {
		 if(k >= k1) {
			tot--;
			ans++;
			k -= k1;
		}
		else
			break;
	}
	cout << ans << endl;
	
	return 0; 
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值