#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define type long long
using namespace std;
pair<pair<type, type>, int > tab1[100033];
pair<pair<type, type>, int > tab2[100033];
// int res[100033];
bool cmp1(pair<pair<type, type>, int > p1, pair<pair<type, type>, int > p2)
{
return p1.first.first < p2.first.first;
}
bool cmp2(pair<pair<type, type>, int > p1, pair<pair<type, type>, int > p2)
{
return (p1.first.second > p2.first.second);
}
int main()
{
cin.tie(NULL);
std::ios::sync_with_stdio(false);
int n;
type z;
cin>>n>>z;
int n1, n2;
n1 = 0;
n2 = 0;
for(int i=0; i<n; i++)
{
type t1, t2;
cin>>t1>>t2;
if(t1 <= t2 )
tab1[n1++] = make_pair(make_pair(t1,t2), i+1);
else
tab2[n2++] = make_pair(make_pair(t1,t2), i+1);
}
sort(tab1, tab1 + n1, cmp1);
sort(tab2, tab2 + n2, cmp2);
// int t = 0;
// cout<<n1<<" "<<n2<<"\n";
bool ok = true;
for(int i=0; i<n1 && ok; i++)
{
type x = tab1[i].first.first;
type y = tab1[i].first.second;
z -= x;
if(z > 0)
z += y;
else
ok = false;
}
for(int i=0; i<n2 && ok; i++)
{
type x = tab2[i].first.first;
type y = tab2[i].first.second;
z -= x;
if(z > 0)
z += y;
else
ok = false;
}
if(ok)
{
cout<<"TAK\n";
for(int i=0; i<n1; i++)
cout<<tab1[i].second<<" ";
for(int i=0; i<n2; i++)
cout<<tab2[i].second<<" ";
cout<<"\n";
}
else
cout<<"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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include <iostream> #include <string> #include <stdlib.h> #include <time.h> #include <math.h> #include <vector> #include <map> #include <queue> #include <algorithm> #define type long long using namespace std; pair<pair<type, type>, int > tab1[100033]; pair<pair<type, type>, int > tab2[100033]; // int res[100033]; bool cmp1(pair<pair<type, type>, int > p1, pair<pair<type, type>, int > p2) { return p1.first.first < p2.first.first; } bool cmp2(pair<pair<type, type>, int > p1, pair<pair<type, type>, int > p2) { return (p1.first.second > p2.first.second); } int main() { cin.tie(NULL); std::ios::sync_with_stdio(false); int n; type z; cin>>n>>z; int n1, n2; n1 = 0; n2 = 0; for(int i=0; i<n; i++) { type t1, t2; cin>>t1>>t2; if(t1 <= t2 ) tab1[n1++] = make_pair(make_pair(t1,t2), i+1); else tab2[n2++] = make_pair(make_pair(t1,t2), i+1); } sort(tab1, tab1 + n1, cmp1); sort(tab2, tab2 + n2, cmp2); // int t = 0; // cout<<n1<<" "<<n2<<"\n"; bool ok = true; for(int i=0; i<n1 && ok; i++) { type x = tab1[i].first.first; type y = tab1[i].first.second; z -= x; if(z > 0) z += y; else ok = false; } for(int i=0; i<n2 && ok; i++) { type x = tab2[i].first.first; type y = tab2[i].first.second; z -= x; if(z > 0) z += y; else ok = false; } if(ok) { cout<<"TAK\n"; for(int i=0; i<n1; i++) cout<<tab1[i].second<<" "; for(int i=0; i<n2; i++) cout<<tab2[i].second<<" "; cout<<"\n"; } else cout<<"NIE\n"; return 0; } |
English