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 (1≤n≤2⋅105,1≤a,b,k≤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 nn integers h1,h2,…,hnh1,h2,…,hn (1≤hi≤1091≤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

时间: 2024-11-06 15:43:50

Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)的相关文章

Codeforces Round #617 (Div. 3) D. Fight with Monsters

题意:打怪,拿分,不同就是可以让别人跳过打怪哪一个环节,不过只有k次 题解:算出每个怪消耗的k,排序 ,贪心 原文地址:https://www.cnblogs.com/RE-TLE/p/12288935.html

Codeforces - 102222H - Fight Against Monsters - 贪心

https://codeforc.es/gym/102222/problem/H 题意:有一堆怪兽,怪兽有HP和ATK.你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽.打的伤害递增,第一次1,第二次2,以此类推. 为什么感觉是贪心呢?证明一波. 首先开始打一个怪兽肯定一直打到死为止.那么打死他要求的次数可以二分出来(其实暴力也可以).两只怪兽交换打的顺序会不会变好? 先打第一只怪兽: \(num_1*sumatk+num_2*(sumatk-atk_1)\) 先打第二只怪兽: \(nu

Codeforces 631 (Div. 2) E. Drazil Likes Heap 贪心

https://codeforces.com/contest/1330/problem/E 有一个高度为h的大顶堆:有2h -1个不同的正整数,下标从1到2h−1,1<i<2h, a[i]<a[⌊i/2⌋]. 现在我们要降低堆的高度,为h,有2g-1个整数,那么我们要删掉2h-2g个数: 选择索引 i 删除,删除方法如下: 被删除的节点值为0,代表该节点不存在. 所以操作后,2g-1个元素的下标在[1,2g-1]范围内:使得剩余元素的总和最小,并且输出调用删除函数时删除的节点下标. 人话

Codeforces Round #617 (Div. 3) 题解

目录 Codeforces Round #617 (Div. 3) 题解 前言 A. Array with Odd Sum 题意 做法 程序 B. Food Buying 题意 做法 程序 C. Yet Another Walking Robot 题意 做法 程序 D. Fight with Monsters 题意 做法 程序 E1. String Coloring (easy version) 题意 做法 程序 E2. String Coloring (hard version) 题意 做法

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(

Codeforces Round #617 (Div. 3) 补题记录

1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需要把数组中其中一个奇(偶)数改成偶(奇)数,相当于加一减一 所以测一下这个数组如果有个奇数并且还有个偶数就行 #include <cstdio> #include <iostream> #include <map> #include <set> #include

Codeforces #258 Div.2 E Devu and Flowers

大致题意: 从n个盒子里面取出s多花,每个盒子里面的花都相同,并且每个盒子里面花的多数为f[i],求取法总数. 解题思路: 我们知道如果n个盒子里面花的数量无限,那么取法总数为:C(s+n-1, n-1) = C(s+n-1, s). 可以将问题抽象成:x1+x2+...+xn = s, 其中0<=xi <= f[i],求满足条件的解的个数. 两种方法可以解决这个问题: 方法一:这个问题的解可以等价于:mul = (1+x+x^2+...+x^f[1])*(1+x+x^2+...+x^f[2]

Codeforces #259 Div.2

A. Little Pony and Crystal Mine 模拟题. 用矩阵直接构造或者直接根据关系输出 B. Little Pony and Sort by Shift 模拟题. 通过提供的操作得到的序列只能是两段递增或者整个序列递增. 那么可以求得第一段递增序列长度为0-p 如果整个序列是递增,即 p= n-1 那么操作次数就是0. 否则,假设是两段递增,把原始的序列恢复出来,设当前序列是AB,那么A就是0-p BA = (A'B')', '表示对序列进行翻转, 如果BA是有序的,那么需

Codeforces #250 (Div. 2) C.The Child and Toy

之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小,肯定拆相应权值较小的 在这个基础上考虑问题就能够了 代码例如以下: #include <cstdio> #include <iostream> #include <algorithm> #define MAXN 10010 #define ll long long usi