能量收集

能量收集

贪心题

就两种操作,收集能量/ 回血 (防护也是回血)

能收集能量就先疯狂收集,最后如果耐久不够了,找之前的耗损耐久最大的一天补回来。(大根堆维护)

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=1e5+10;
inline int read() {
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
void write(int x) {
	static short st[32];short tp=0;
	do st[++tp]=x%10,x/=10;while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar('\n');
}
int n,x,y,tol,energy;
int mx=0,d[N];
priority_queue<int>q; 
int main() {
	n=read();x=read();y=read();tol=read();energy=read();
	for(int i=1;i<=n;i++) d[i]=read();//damage
	int now=0;
	for(int i=1;i<=n;i++) {
		q.push(max(y,d[i]));
		now+=x;
		mx=max(mx,now);
		if(now>=energy) {
			puts("YES");
			write(i);
			return 0;
		} 
		tol-=d[i];
		while(tol<=0&&q.size()) now-=x,tol+=q.top(),q.pop();
	}
	puts("NO");
	write(mx);
	return 0;
}

posted @ 2020-11-09 21:17  ke_xin  阅读(256)  评论(0编辑  收藏  举报