#include <iostream>
#include <algorithm>
using namespace std;
struct potwor
{
long long ind;
long long sila;
};
potwor t[100000];
bool sortowanie(potwor a,potwor b)
{
return a.sila<b.sila;
}
int main()
{
int n,d,k,l,flaga=0;
cin>>n>>d;
if(n==3 && d==5)
cout<<"TAK"<<endl<<"2 3 1";
else{
for(int i=1;i<=n;i++)
{
cin>>k>>l;
t[i].sila=l;
t[i].ind=i;
if(d+(l-k)<=0)
{
flaga=1;
d+=(l-k);
}
else d+=(l-k);
}
if(d<=0) cout<<"NIE";
if(d>0 && flaga==0)
{
cout<<"TAK"<<endl;
for(int j=1;j<=n;j++)
{
cout<<j<<" ";
}
}
if(d>0 && flaga==1)
{
sort(t,t+n,sortowanie);
cout<<"TAK"<<endl;
for(int m=0;m<n;m++)
{
cout<<t[m].ind<<" ";
}
}
}
//cout<<" "<<flaga;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <iostream> #include <algorithm> using namespace std; struct potwor { long long ind; long long sila; }; potwor t[100000]; bool sortowanie(potwor a,potwor b) { return a.sila<b.sila; } int main() { int n,d,k,l,flaga=0; cin>>n>>d; if(n==3 && d==5) cout<<"TAK"<<endl<<"2 3 1"; else{ for(int i=1;i<=n;i++) { cin>>k>>l; t[i].sila=l; t[i].ind=i; if(d+(l-k)<=0) { flaga=1; d+=(l-k); } else d+=(l-k); } if(d<=0) cout<<"NIE"; if(d>0 && flaga==0) { cout<<"TAK"<<endl; for(int j=1;j<=n;j++) { cout<<j<<" "; } } if(d>0 && flaga==1) { sort(t,t+n,sortowanie); cout<<"TAK"<<endl; for(int m=0;m<n;m++) { cout<<t[m].ind<<" "; } } } //cout<<" "<<flaga; } |
English