Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)

There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health points (hp). You have your attack power equal to aa hp and your opponent has his attack power equal to bb 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.

  1. You hit the monster by aa hp. If it is dead after your hit, you gain one point and you both proceed to the next monster.
  2. Your opponent hits the monster by bb 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 kk times in total (for example, if there are two monsters and k=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,bn,a,b and kk (1n2105,1a,b,k1091≤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 nn integers h1,h2,,hnh1,h2,…,hn (1hi1091≤hi≤109 ), where hihi is the health points of the ii -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
读入的时候进行预处理,先模一下a+b,如果变成0了的话+b,不为零的话-a。本质上都是看在不跳过的情况下,最后一轮里自己攻击后处于什么状况。然后对数组由小到大排序。这里有一个贪心的思想,因为在此之后都是要靠k次跳过对手的攻击,所以说怪物剩余血量越少对自己越有利,这样能尽可能用较少的跳过次数把怪KO。之后遍历数组统计分数,同时相应的减去跳过次数。
#include <bits/stdc++.h>
using namespace std;
int n,a,b,k;
int h[200005];
long long ans=0;
int main()
{
    cin>>n>>a>>b>>k;
    int i;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&h[i]);
        h[i]%=(a+b);
        if(h[i]==0)h[i]+=b;
        else h[i]-=a;
    }
    sort(h+1,h+n+1);
    for(i=1;i<=n;i++)
    {
        if(h[i]<=0)
        {
            ans++;//血量小于0说明最后一轮自己能直接获得人头
            continue;
        }
        else
        {
            if(h[i]-k*a<=0)
            {
                ans++;
                if(h[i]%a==0)k-=h[i]/a;
                else k-=(h[i]/a+1);
            }
            else
            {
                continue;
            }        
        }
    }
    cout<<ans<<endl;

    return 0;
}



 
原文地址:https://www.cnblogs.com/lipoicyclic/p/12268849.html