其他分享
首页 > 其他分享> > 3709. [PA2014]Bohater

3709. [PA2014]Bohater

作者:互联网

原文链接:http://hzwer.com/4402.html

题解

注意初值不要设成0x3f;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define ll long long 
using namespace std;
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 x*f;
}
int n,t1,t2;
ll z;
struct data{int d,a,id;}a[100005],b[100005];
bool cmp1(data a,data b)
{
	return a.d<b.d;
}
bool cmp2(data a,data b)
{
	return a.a>b.a;
}
int main()
{
	n=read();z=read();
	for(int i=1;i<=n;i++)
	{
		int x=read(),y=read();
		if(x<=y)a[++t1].d=x,a[t1].a=y,a[t1].id=i;
		else b[++t2].d=x,b[t2].a=y,b[t2].id=i;
	}
	sort(a+1,a+t1+1,cmp1);
	for(int i=1;i<=t1;i++)
		if(z<=a[i].d){puts("NIE");return 0;}
		else z=z-a[i].d+a[i].a;
	sort(b+1,b+t2+1,cmp2);
	for(int i=1;i<=t2;i++)
		if(z<=b[i].d){puts("NIE");return 0;}
		else z=z-b[i].d+b[i].a;
	puts("TAK");
	for(int i=1;i<=t1;i++)
		printf("%d ",a[i].id);
	for(int i=1;i<=t2;i++)
		printf("%d ",b[i].id);
	return 0;
}

 

标签:ch,Bohater,int,PA2014,long,read,3709,include,getchar
来源: https://blog.csdn.net/qq_37347127/article/details/99880898