D. Fight with Monsters
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There are 𝑛n monsters standing in a row numbered from 11 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 00.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 𝑘=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,b and
𝑘k (1≤𝑛≤2⋅105,1≤𝑎,𝑏,𝑘≤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 𝑛n integers
ℎ1,ℎ2,…,ℎ𝑛h1,h2,…,hn (1≤ℎ𝑖≤1091≤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
Copy
6 2 3 3
7 10 50 12 1 8
output
Copy
5
input
Copy
1 1 100 99
100
output
Copy
1
input
Copy
7 4 2 1
1 3 5 4 2 7 6
output
Copy
6
思路如下
- 题意:有一个地方需要注意,每打倒一只怪兽,到另一只👾的面前,总是“你” 先进行 攻击🔧
- 思路:理解了 👆所说的之后就很简单了,我们要做的就是一次求出 杀死每一头 怪兽 所需要的 “tenique” 的次数(直接看 代码),然后 sort 排序,依次 把使用 “tenique” 较少的选了就行了
题解如下
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, a, b, k;
cin >> n >> a >> b >> k;
vector<int> h(n);
for (int i = 0; i < n; ++i) {
cin >> h[i];
h[i] %= a + b;
if (h[i] == 0) h[i] += a + b;
h[i] = ((h[i] + a - 1) / a) - 1;
}
sort(h.begin(), h.end());
int ans = 0;
for (int i = 0; i < n; ++i) {
if (k - h[i] < 0) break;
++ans;
k -= h[i];
}
cout << ans << endl;
return 0;
}