//============================================================================ // Name : boh.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdlib.h> using namespace std; int d[100000], a[100000], i[100000], dif[100000]; int compare_function(const void *a,const void *b) { int *pa = (int *)a, *pb = (int *)b; int va = *pa, vb = *pb; int i1 = va; int i2 = vb; if(dif[i1]>0 && dif[i2]<=0) return -1; if(dif[i1]<=0 && dif[i2]>0) return 1; if(dif[i1]>0) return d[i1] - d[i2]; return d[i2] - d[i1]; } int main() { ios_base::sync_with_stdio(0); int n; long long p; cin >> n >> p; for(int ind=0; ind<n; ind++) { i[ind] = ind; cin >> d[ind] >> a[ind]; dif[ind] = a[ind] - d[ind]; } qsort(i, n, sizeof(i[0]), compare_function); for(int ind=0; ind<n; ind++) { p-=d[i[ind]]; if(p<=0) { cout << "NIE"; return 0; } p+=a[i[ind]]; } cout << "TAK" << endl; for(int ind=0; ind<n; ind++) { cout << i[ind]+1 << ' '; } 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 | //============================================================================ // Name : boh.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdlib.h> using namespace std; int d[100000], a[100000], i[100000], dif[100000]; int compare_function(const void *a,const void *b) { int *pa = (int *)a, *pb = (int *)b; int va = *pa, vb = *pb; int i1 = va; int i2 = vb; if(dif[i1]>0 && dif[i2]<=0) return -1; if(dif[i1]<=0 && dif[i2]>0) return 1; if(dif[i1]>0) return d[i1] - d[i2]; return d[i2] - d[i1]; } int main() { ios_base::sync_with_stdio(0); int n; long long p; cin >> n >> p; for(int ind=0; ind<n; ind++) { i[ind] = ind; cin >> d[ind] >> a[ind]; dif[ind] = a[ind] - d[ind]; } qsort(i, n, sizeof(i[0]), compare_function); for(int ind=0; ind<n; ind++) { p-=d[i[ind]]; if(p<=0) { cout << "NIE"; return 0; } p+=a[i[ind]]; } cout << "TAK" << endl; for(int ind=0; ind<n; ind++) { cout << i[ind]+1 << ' '; } return 0; } |