80分求助!
查看原帖
80分求助!
600517
chenmaheng楼主2023/6/3 09:20
#include <bits/stdc++.h>
using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */
const int MAX = 1e5 + 5;
struct gs
{
	int d,a,id;
}a[MAX],b[MAX];
int cmp1(gs x,gs y)
{
	return x.d < y.d;
}
int cmp2(gs x,gs y)
{
	return x.a > y.a;
}
int main(int argc, char** argv) {
	long long n,z;
	cin >> n >> z;
	int cnt1 = 0;
	int cnt2 = 0;
	for(int i = 1;i <= n;i++)
	{
		int td,ta;
		cin >> td >> ta;
		
		if(td < ta)
		{
			a[++cnt1].d = td;
			a[cnt1].a = ta;
			a[cnt1].id = i; 
		}
		else
		{
			b[++cnt2].d = td;
			b[cnt2].a = ta;
			b[cnt2].id = i; 
		}
	}
	sort(a+1,cnt1+a+1,cmp1);
	sort(b+1,cnt2+b+1,cmp2);
	for(int i = 1;i <= cnt1;i++)
	{
		if(z <= a[i].d)
		{
			cout << "NIE" << endl;
			return 0;
		}
		z = z+a[i].a - a[i].d;
	}
	for(int i = 1;i <= cnt1;i++)//DEBUG!
	{
		if(z <= b[i].d)
		{
			cout << "NIE" << endl;
			return 0;
		}
		z = z+b[i].a - b[i].d;
	}
	cout << "TAK" << endl;
	for(int i =1;i <= cnt2;i++)   
	{
		cout << a[i].id << " ";
	}   
	for(int i =1;i <= cnt1;i++)   
	{
		cout << b[i].id << " ";
	}               
	return 0;
}
2023/6/3 09:20
加载中...