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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
// Bohater2.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

long long life;
int n;

struct data
{
	long long damage;
	long long health;
	int nr;
};

vector<data> enemies;
vector<int> result;

bool cmp (data d1,data d2) { return ( d1.health - d1.damage > d2.health - d2.damage); }

bool calc()
{
	while (!enemies.empty())
	{
		int found = -1;
		double diff = enemies[0].health - enemies[0].damage;
		if (diff >= 0)
		{
			for (int i = 0; i < enemies.size(); ++i)
			{
				data d = enemies[i];
				if (d.damage < life)
				{
					found = i;
					break;
				}
			}
		}
		else
		{
			for (int i = enemies.size()-1; i >= 0; --i)
			{
				data d = enemies[i];
				if (d.damage < life)
				{
					found = i;
					break;
				}
			}
		}
	
		if (found != -1)
		{
			life = life - enemies[found].damage + enemies[found].health;
			result.push_back(enemies[found].nr);
			enemies.erase(enemies.begin() + found);
		}
		else
		{
			return false;
		}
	}
	return true;
}

int main()
{
	cin >> n >> life;
	long long a, b;
	for (int i = 0 ; i < n; ++i)
	{
		cin >> a >> b;
		data d;
		d.damage = a;
		d.health = b;
		d.nr = i+1;
		enemies.push_back(d);
	}

	sort(enemies.begin(), enemies.end(), cmp);

	if (calc())
	{
		cout << "TAK" << endl;
		for (int i = 0; i < n; i++)
		{
			cout << result[i] << " ";
		}
	}
	else
	{
		cout << "NIE" << endl;
	}

	return 0;
}