D. Fight with Monsters

本文探讨了一种游戏策略,玩家需与对手合作对抗一系列怪物,目标是在限制条件下使用特殊技巧来最大化个人得分。通过算法优化,确定了如何在攻击怪物时最佳利用特殊技巧。

链接:https://codeforces.com/contest/1296/problem/D

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

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

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,a,b,k,t,g,ans,s,max1=0; 
long long x[1000001],c[1000001];
int main()
{
    cin>>n>>a>>b>>k;
   	t=1; 
   	s=0;
   	long long j=0;
    for(int i=1;i<=n;i++)
    {
    	cin>>x[i];
    	x[i]=((x[i]-1)%(a+b))/a;
    }
    sort(x+1,x+1+n);
    for(int i=1;i<=n;i++)
    {
    	k-=x[i];
    	if(k>=0)
    	{
    		s++;
    	}
    	else
    	break;
    }
    cout<<s<<endl;
}

 

c++:Problem Statement Takahashi is about to play a game where he fights N monsters in order. Initially, Takahashi's health is H and his magic power is M. For the i-th monster he fights, he can choose one of the following actions: Fight without using magic. This can only be chosen when his health is at least A i ​ , and his health decreases by A i ​ and the monster is defeated. Fight using magic. This can only be chosen when his magic power is at least B i ​ , and his magic power decreases by B i ​ and the monster is defeated. The game ends when all N monsters are defeated or when he cannot take any action. What is the maximum number of monsters he can defeat before the game ends? Constraints 1≤N≤3000 1≤H,M≤3000 1≤A i ​ ,B i ​ ≤3000 All input values are integers. Input The input is given from Standard Input in the following format: N H M A 1 ​ B 1 ​ A 2 ​ B 2 ​ ⋮ A N ​ B N ​ Output Output the answer. Sample Input 1 Copy 4 10 14 5 8 5 6 7 9 99 99 Sample Output 1 Copy 3 By taking the following actions, Takahashi can defeat 3 monsters before the game ends. Initially, his health is 10 and his magic power is 14. Fight the 1st monster without using magic. His health decreases by 5, becoming health 5 and magic power 14. Fight the 2nd monster without using magic. His health decreases by 5, becoming health 0 and magic power 14. Fight the 3rd monster using magic. His magic power decreases by 9, becoming health 0 and magic power 5. For the 4th monster, he cannot choose either action, so the game ends. Sample Input 2 Copy 3 3000 3000 3 3 3 3 3 3 Sample Output 2 Copy 3 He may be able to defeat all monsters. Sample Input 3 Copy 10 8 8 2 2 2 3 2 2 1 2 2 3 1 2 3 3 3 2 3 1 3 2 Sample Output 3 Copy 9
最新发布
06-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值