80pts求调
查看原帖
80pts求调
1268907
wangcm楼主2024/9/10 19:42
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int xh;
	int hx;
}d[100001];
bool cmp(node x,node y)
{
	return (x.hx-x.xh)>(y.hx-y.xh);
}
bool cmp2(node x,node y)
{
	if(x.xh-x.hx<0&&y.xh-y.hx<0){
		return x.xh<y.xh;
	}
	return (x.hx-x.xh)>(y.hx-y.xh);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,z;
	cin>>n>>z;
	int h=z;
	for(int i=0;i<n;i++)
	{
		cin>>d[i].xh>>d[i].hx;
	}
	sort(d,d+n,cmp);
	sort(d,d+n,cmp2);
	string sdf="TAK";
	bool bn=true;
	for(int i=0;i<n;i++){
		int xl=d[i].hx-d[i].xh;
		h+=xl;
		if(h<=0){
			sdf="NIE";
			bn=false;
		}
	}
	if(bn){
		cout<<sdf;
		return 0;
	} 
	else{
		for(int i=0;i<n;i++){
			h-=d[i].xh;
			if(h<=0){
				sdf="NIE";
			}
			h+=d[i].hx;
		}
	}
	cout<<sdf;
	
	return 0;
}
2024/9/10 19:42
加载中...