#include<iostream> #include<algorithm> #include<vector> using namespace std; class Node { public: int index; int value; Node ( int index, int value) { this->index = index; this->value = value; } }; bool myfunction (Node i,Node j) { return ( i.value > j.value ); } int main() { int n,z,d,a; cin >> n; cin >> z; if ( z <= 0 ) { cout << "NIE" << endl; return 0; } vector<Node> myvector; for ( int i = 1; i <= n; ++i ) { cin >> d; cin >> a; myvector.push_back( Node(i, a-d ) ); } sort(myvector.begin(), myvector.end(), myfunction); long long int sum = z; for (std::vector<Node>::iterator it=myvector.begin(); it!=myvector.end(); ++it) { sum += it->value; } if ( sum > 0 ) { cout << "TAK" << endl; for (std::vector<Node>::iterator it=myvector.begin(); it!=myvector.end(); ++it) { cout << it->index << " "; } } else { cout << "NIE" << endl; } 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 | #include<iostream> #include<algorithm> #include<vector> using namespace std; class Node { public: int index; int value; Node ( int index, int value) { this->index = index; this->value = value; } }; bool myfunction (Node i,Node j) { return ( i.value > j.value ); } int main() { int n,z,d,a; cin >> n; cin >> z; if ( z <= 0 ) { cout << "NIE" << endl; return 0; } vector<Node> myvector; for ( int i = 1; i <= n; ++i ) { cin >> d; cin >> a; myvector.push_back( Node(i, a-d ) ); } sort(myvector.begin(), myvector.end(), myfunction); long long int sum = z; for (std::vector<Node>::iterator it=myvector.begin(); it!=myvector.end(); ++it) { sum += it->value; } if ( sum > 0 ) { cout << "TAK" << endl; for (std::vector<Node>::iterator it=myvector.begin(); it!=myvector.end(); ++it) { cout << it->index << " "; } } else { cout << "NIE" << endl; } return 0; } |