题目大意:
中文题,题目链接
题解:
两种情况:
可以回血的先打,按掉血从小到大打
掉血的话,按回血从大到小打。
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int N=100100;
int n;
ll z;
struct node{
int x,y,id;
}sa[N];
struct node1{
int x,y,id;
}sb[N];
int ans[N];
bool cmp(node1 x,node1 y)
{
return x.x<y.x;
}
bool cmp1(node x,node y)
{
return x.y>y.y;
}
int main()
{
scanf("%d%lld",&n,&z);
int cnt=0,len=0,sum=0;
int x,y;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(y-x>0)
{
cnt++;
sb[cnt].x=x;
sb[cnt].y=y;
sb[cnt].id=i;
}
else
{
len++;
sa[len].x=x;
sa[len].y=y;
sa[len].id=i;
}
}
sort(sb+1,sb+1+cnt,cmp);
for(int i=1;i<=cnt;i++)
{
z-=sb[i].x;
if(z<=0)
{
printf("NIE\n");
return 0;
}
z+=sb[i].y;
ans[++sum]=sb[i].id;
}
sort(sa+1,sa+1+len,cmp1);
for(int i=1;i<=len;i++)
{
z-=sa[i].x;
if(z<=0)
{
printf("NIE\n");
return 0;
}
z+=sa[i].y;
ans[++sum]=sa[i].id;
}
printf("TAK\n");
for(int i=1;i<=sum;i++) printf("%d ",ans[i]);
}