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
#include<stdio.h>
#include<queue>
#include<utility>
using namespace std;

int n,z,i,tmp1,tmp2;
priority_queue<pair<int,pair<int,int> > > q;
queue<pair<int,pair<int,int> > > tmp;
queue<int> w;

int main(void)
{
    scanf("%d %d",&n,&z);
    for(i=0;i<n;++i)
    {
        scanf("%d %d",&tmp1,&tmp2);
        q.push(make_pair(tmp2-tmp1,make_pair(tmp1,i+1)));
    }
    for(;!q.empty();)
    {
        while(!q.empty() && (q.top().second.first >= z)){tmp.push(q.top());q.pop();}
        if(q.empty()){printf("NIE");return 0;}
        z=z+q.top().first;w.push(q.top().second.second);q.pop();
        while(!tmp.empty()){q.push(tmp.front());tmp.pop();}
    }
    printf("TAK\n");
    for(;!w.empty();){printf("%d ",w.front());w.pop();}
    return 0;
}