#include <cstdio>
#include <vector>
#include <algorithm>
#define PB push_back
using namespace std;
int n, z, a, b;
long long aktual;
struct par{
int first;
int second;
int numer;
};
vector<par > dobre;
vector<par> zle;
par MP(int a, int b, int c)
{
par p;
p.first=a;
p.second=b;
p.numer=c;
return p;
}
bool pordobre(par a, par b)
{
if(a.first<b.first)
return true;
if(a.first>b.first)
return false;
return a.numer<b.numer;
}
bool porzle(par a, par b)
{
if(a.second>b.second)
return true;
if(a.second<b.second)
return false;
return a.numer<b.numer;
}
vector<int> wynvec;
int main()
{
scanf("%d%d", &n, &z);
for (int i=0; i<n; i++)
{
scanf("%d%d", &a, &b);
if (a<=b)
dobre.PB(MP(a, b, i+1));
else
zle.PB(MP(a, b, i+1));
}
sort(dobre.begin(), dobre.end(), pordobre);
sort(zle.begin(), zle.end(), porzle);
aktual=z;
bool czy=true;
for (int i=0; i<dobre.size()&&czy; i++)
{
if(dobre[i].first>=aktual)
czy=false;
else
{
aktual+=(dobre[i].second-dobre[i].first);
wynvec.PB(dobre[i].numer);
}
}
for (int i=0; i<zle.size()&&czy; i++)
{
if(zle[i].first>=aktual)
czy=false;
else
{
aktual+=(zle[i].second-zle[i].first);
wynvec.PB(zle[i].numer);
}
}
if (czy)
{
printf("TAK\n");
for (int i=0; i<wynvec.size(); i++)
{
printf("%d ", wynvec[i]);
}
printf("\n");
}
else
printf("NIE\n");
return 0;
}
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 | #include <cstdio> #include <vector> #include <algorithm> #define PB push_back using namespace std; int n, z, a, b; long long aktual; struct par{ int first; int second; int numer; }; vector<par > dobre; vector<par> zle; par MP(int a, int b, int c) { par p; p.first=a; p.second=b; p.numer=c; return p; } bool pordobre(par a, par b) { if(a.first<b.first) return true; if(a.first>b.first) return false; return a.numer<b.numer; } bool porzle(par a, par b) { if(a.second>b.second) return true; if(a.second<b.second) return false; return a.numer<b.numer; } vector<int> wynvec; int main() { scanf("%d%d", &n, &z); for (int i=0; i<n; i++) { scanf("%d%d", &a, &b); if (a<=b) dobre.PB(MP(a, b, i+1)); else zle.PB(MP(a, b, i+1)); } sort(dobre.begin(), dobre.end(), pordobre); sort(zle.begin(), zle.end(), porzle); aktual=z; bool czy=true; for (int i=0; i<dobre.size()&&czy; i++) { if(dobre[i].first>=aktual) czy=false; else { aktual+=(dobre[i].second-dobre[i].first); wynvec.PB(dobre[i].numer); } } for (int i=0; i<zle.size()&&czy; i++) { if(zle[i].first>=aktual) czy=false; else { aktual+=(zle[i].second-zle[i].first); wynvec.PB(zle[i].numer); } } if (czy) { printf("TAK\n"); for (int i=0; i<wynvec.size(); i++) { printf("%d ", wynvec[i]); } printf("\n"); } else printf("NIE\n"); return 0; } |
English