怪物补刀(贪心)

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.
n只怪兽站成一排,从1到n。第i只怪兽有hi的血量,你的攻击力为a,对手的攻击力为b。

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.
你和你的竞争者需要对抗这些怪兽,从第一只怪兽开始,只有击败后才能移动到第二只,依次往后。怪兽的hp为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).
你有一种能力,能够让你的对手跳过一回合。你最多能够使用k次。

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

解题思路:

1.本题目的目的是分数,直接相关的就是自己打死的怪物的数量。自己的技能应该用在 自己容易打死的。关键是寻找什么是容易打死的。
2.在某个回合结束后,自己再用一招毙命的,这是最容易打死的。其次就是用更少的技能自己打死的。
3.为了使分数更高,应把怪物按 容易度排个名次,把技能用在容易打死的怪物身上。

源码:

#include
using namespace std;
int score()
{
    vector<int> v;
    int n,a,b,k,h,d,c,ans=0;
    cin>>n>>a>>b>>k;
    int s=a+b;
    while(n--)
    {
        cin>>h;
        d=(h-1)%s+1;
        if(d<=a)
            ans++;
        else
            v.push_back(d);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        c=(v[i]-1)/a;
        if(c<=k)
        {
            k=k-c;
            ans++;
        }
        else
            return ans;
    }
}
int main()
{
    cout<<score()<<endl;
}

你可能感兴趣的:(算法,c++)