题解 | 狩影·进击
狩影·进击
https://www.nowcoder.com/practice/eb369aaf477d464b9fa0ca972557f623
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
long long k;
cin>>n>>k;
priority_queue<long long>dam;//因为巨人要采取最优策略,所以会先吃伤害最高的企鹅,用大顶堆存
long long hurt=0;//存储一个每秒总伤害方便计算
for(int i=1;i<=n;i++){
long long x;
cin>>x;
dam.push(x);
hurt+=x;
}
long long hp;
int x;
cin>>hp>>x;
long long time=0;
while(++time){
long long dam_time=min(hurt,k);//每秒伤害取min(每秒可造成的伤害,企鹅可造成的伤害)
hp-=dam_time;
if(time%x==0){//表示吃了一只企鹅
time=0;
hurt=hurt-dam.top();//总伤害要降低
dam.pop();//删除该企鹅
}
//每秒结束时进行胜负的条件判断
if(hp<0){
cout<<"YES\n";
break;
}
if(dam.empty() && hp>=0){
cout<<"NO\n";
break;
}
}
}
return 0;
}
