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; 
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章