BZOJ 3709: [PA2014]Bohater 贪心

3709: [PA2014]Bohater

Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special Judge
Submit: 1410  Solved: 484
[Submit][Status][Discuss]

Description

在一款电脑游戏中,你需要打败n只怪物(从1到n编号)。为了打败第i只怪物,你需要消耗d[i]点生命值,但怪物死后会掉落血药,使你恢复a[i]点生命值。任何时候你的生命值都不能降到0(或0以下)。请问是否存在一种打怪顺序,使得你可以打完这n只怪物而不死掉

Input

第一行两个整数n,z(1<=n,z<=100000),分别表示怪物的数量和你的初始生命值。
接下来n行,每行两个整数d[i],a[i](0<=d[i],a[i]<=100000)

Output

第一行为TAK(是)或NIE(否),表示是否存在这样的顺序。
如果第一行为TAK,则第二行为空格隔开的1~n的排列,表示合法的顺序。如果答案有很多,你可以输出其中任意一个。

Sample Input

3 5
3 1
4 8
8 3

Sample Output

TAK
2 3 1

贪心

先搞加血,再搞减血

加血不用说,减血时

i在j前,一定有

max(d[i],d[i]-a[i]+d[j])<max(d[j],d[j]-a[j]+d[i])


记得开long long

#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

typedef long long ll;
typedef double db;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=100100;

ll n,m,ans[N];

struct P{int a,d,pos;friend bool operator <(const P &x,const P &y){return  x.d>y.d;}};

struct node{int a,d,pos;friend bool operator <(const node &x,const node &y){return x.a<y.a;}};

priority_queue<P>q;

priority_queue<node>Q;

int main()
{
	n=read();m=read();
	register int i,x,y,j=0;
	for(i=1;i<=n;++i)
	{
		x=read();y=read();
		if(y>=x)q.push((P){y-x,x,i});
		else Q.push((node){y,x,i});
	}
	P u;
	while(!q.empty())
	{
		u=q.top();q.pop();
		if(m<=u.d){puts("NIE");return 0;}
		m+=u.a;ans[++j]=u.pos;
	}
	node v;
	while(!Q.empty())
	{
		v=Q.top();Q.pop();
		if(m<=v.d){puts("NIE");return 0;}
		m-=v.d;m+=v.a;ans[++j]=v.pos;
	}
	puts("TAK");
	for(i=1;i<j;++i)print(ans[i]),putchar(' ');print(ans[j]);puts("");
	return 0;
}
/*
3 5
3 1
4 8
8 3

TAK
2 3 1
*/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值