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
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair< pair<int,int>,int> smok;
vector<smok> dod,uje;
bool gr (const smok a,const smok b)
{
return a.first.second>b.first.second;
}

vector<int> wyn;
int main()
{
int n,z1;
 long long z;
int d,a;
int ndod,nuj;
ndod=nuj=0;
scanf("%d %d",&n,&z1);
z=z1;

for (int i=1;i<n+1;i++)
{
scanf("%d %d",&d,&a);
if(a-d>=0) {
ndod++;
dod.push_back(make_pair(make_pair(d,a),i));
}
// smoki dodatnie;
else {
nuj++;
uje.push_back(make_pair(make_pair(d,a),i));
//smoki ujemne
}
}
sort(dod.begin(),dod.end());
sort(uje.begin(),uje.end(),gr);
for (int i=0;i<ndod&&z>0;i++){
z-=dod[i].first.first;
//z1-=dod[i].first.first;
if(z>0) {z+=dod[i].first.second;wyn.push_back(dod[i].second);}
}
for (int i=0;i<nuj&&z>0;i++){
z-=uje[i].first.first;
//z1-=uje[i].first.first;
if(z>0) {z+=uje[i].first.second; wyn.push_back(uje[i].second);}
}
if(z>0) {printf("TAK\n");
for (int i=0;i<n;i++) printf("%d ",wyn[i]);
}
else printf("NIE");

return 0;
}