C. Kill the Monster(枚举暴力)

Monocarp is playing a computer game. In this game, his character fights different monsters.

A fight between a character and a monster goes as follows. Suppose the character initially has health hChC and attack dCdC; the monster initially has health hMhM and attack dMdM. The fight consists of several steps:

  1. the character attacks the monster, decreasing the monster's health by dCdC;
  2. the monster attacks the character, decreasing the character's health by dMdM;
  3. the character attacks the monster, decreasing the monster's health by dCdC;
  4. the monster attacks the character, decreasing the character's health by dMdM;
  5. and so on, until the end of the fight.

The fight ends when someone's health becomes non-positive (i. e. 00 or less). If the monster's health becomes non-positive, the character wins, otherwise the monster wins.

Monocarp's character currently has health equal to hChC and attack equal to dCdC. He wants to slay a monster with health equal to hMhM and attack equal to dMdM. Before the fight, Monocarp can spend up to kk coins to upgrade his character's weapon and/or armor; each upgrade costs exactly one coin, each weapon upgrade increases the character's attack by ww, and each armor upgrade increases the character's health by aa.

Can Monocarp's character slay the monster if Monocarp spends coins on upgrades optimally?

Input

The first line contains one integer tt (1≤t≤5⋅1041≤t≤5⋅104) — the number of test cases. Each test case consists of three lines:

The first line contains two integers hChC and dCdC (1≤hC≤10151≤hC≤1015; 1≤dC≤1091≤dC≤109) — the character's health and attack;

The second line contains two integers hMhM and dMdM (1≤hM≤10151≤hM≤1015; 1≤dM≤1091≤dM≤109) — the monster's health and attack;

The third line contains three integers kk, ww and aa (0≤k≤2⋅1050≤k≤2⋅105; 0≤w≤1040≤w≤104; 0≤a≤10100≤a≤1010) — the maximum number of coins that Monocarp can spend, the amount added to the character's attack with each weapon upgrade, and the amount added to the character's health with each armor upgrade, respectively.

The sum of kk over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, print YES if it is possible to slay the monster by optimally choosing the upgrades. Otherwise, print NO.

Example

input

Copy

4
25 4
9 20
1 1 10
25 4
12 20
1 1 10
100 1
45 2
0 4 10
9 2
69 2
4 2 7

output

Copy

YES
NO
YES
YES

Note

In the first example, Monocarp can spend one coin to upgrade weapon (damage will be equal to 55), then health during battle will change as follows: (hC,hM)=(25,9)→(25,4)→(5,4)→(5,−1)(hC,hM)=(25,9)→(25,4)→(5,4)→(5,−1). The battle ended with Monocarp's victory.

In the second example, Monocarp has no way to defeat the monster.

In the third example, Monocarp has no coins, so he can't buy upgrades. However, the initial characteristics are enough for Monocarp to win.

In the fourth example, Monocarp has 44 coins. To defeat the monster, he has to spend 22 coins to upgrade weapon and 22 coins to upgrade armor.

思路:

1,乘除比循环加减效率要高,

2,遍历0--k,判断不同的增幅的可行性,注意向上取整

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll
#define pu push_back
#define rep(i,m,n) for(int i=m;i<=n;++i)
#define atp(i,m,n) for(int i=m;i>=n;--i)
#define pii pair<int,int>
#define pll pair<long,long>
#define vi vector<int>
#define si set<int>
; const int maxj =2e5+100,mod = 998244353;
int cnt[30];
void solve(){
    int hc,dc,hm,dm;
    int k,w,a;
    cin>>hc>>dc;cin>>hm>>dm;
    cin>>k>>w>>a;//a是血量,数值关系
   
    rep(i,0,k){
        int cnt=k-i;
        hc+=i*a;dc+=cnt*w;//直接作比,效率更高.
      
        if(ceil(hc/double(dm))>=ceil(hm/double(dc))){//向上取整,血量必须<=0,才会死
            cout<<"YES"<<'\n';
            return ;
        }
        hc-=i*a;dc-=cnt*w;
    }
    cout<<"NO"<<'\n';
}
int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值