#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct trojkagood{
int zadane,heal,mob;
trojkagood(int a, int b, int c){
zadane=a;
heal=b;
mob=c;
}
bool operator<(const trojkagood W)
const{
if(zadane<W.zadane) return 1;
if(zadane>W.zadane) return 0;
if(heal>W.heal) return 1;
return 0;
}
};
struct trojkabad{
int zadane,heal,mob;
trojkabad(int a, int b, int c){
zadane=a;
heal=b;
mob=c;
}
bool operator<(const trojkabad W)
const{
if(heal>W.heal) return 1;
if(heal<W.heal) return 0;
if(zadane<W.zadane) return 1;
return 0;
}
} ;
vector <trojkagood> good;
vector <trojkabad> bad;
vector <int> wynikowa;
int main()
{
ios_base::sync_with_stdio(0);
int potwory,zycie,zadane,heal;
cin >> potwory >> zycie;
for(int i=0; i<potwory; i++)
{
cin >> zadane >> heal;
if(heal>=zadane) good.push_back(trojkagood(zadane,heal,i));
else bad.push_back(trojkabad(zadane,heal,i));
}
sort(good.begin(),good.end());
sort(bad.begin(),bad.end());
for(int i=0; i<good.size(); i++)
{
zycie=zycie-good[i].zadane+good[i].heal;
if(zycie<=0){
cout << "NIE";
return 0;
}
wynikowa.push_back(good[i].mob);
}
for(int i=0; i<bad.size(); i++)
{
zycie=zycie-bad[i].zadane+bad[i].heal;
if(zycie<=0){
cout << "NIE";
return 0;
}
wynikowa.push_back(bad[i].mob);
}
cout << "TAK\n";
for(int i=0; i<wynikowa.size(); i++)
cout << wynikowa[i]+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 70 71 72 73 74 75 76 77 78 | #include<iostream> #include<algorithm> #include<vector> using namespace std; struct trojkagood{ int zadane,heal,mob; trojkagood(int a, int b, int c){ zadane=a; heal=b; mob=c; } bool operator<(const trojkagood W) const{ if(zadane<W.zadane) return 1; if(zadane>W.zadane) return 0; if(heal>W.heal) return 1; return 0; } }; struct trojkabad{ int zadane,heal,mob; trojkabad(int a, int b, int c){ zadane=a; heal=b; mob=c; } bool operator<(const trojkabad W) const{ if(heal>W.heal) return 1; if(heal<W.heal) return 0; if(zadane<W.zadane) return 1; return 0; } } ; vector <trojkagood> good; vector <trojkabad> bad; vector <int> wynikowa; int main() { ios_base::sync_with_stdio(0); int potwory,zycie,zadane,heal; cin >> potwory >> zycie; for(int i=0; i<potwory; i++) { cin >> zadane >> heal; if(heal>=zadane) good.push_back(trojkagood(zadane,heal,i)); else bad.push_back(trojkabad(zadane,heal,i)); } sort(good.begin(),good.end()); sort(bad.begin(),bad.end()); for(int i=0; i<good.size(); i++) { zycie=zycie-good[i].zadane+good[i].heal; if(zycie<=0){ cout << "NIE"; return 0; } wynikowa.push_back(good[i].mob); } for(int i=0; i<bad.size(); i++) { zycie=zycie-bad[i].zadane+bad[i].heal; if(zycie<=0){ cout << "NIE"; return 0; } wynikowa.push_back(bad[i].mob); } cout << "TAK\n"; for(int i=0; i<wynikowa.size(); i++) cout << wynikowa[i]+1 << " "; return 0; } |
English