#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct _monster
{
int num;
int str;
int heal;
};
typedef struct _monster monster;
bool compareByStr(const monster &a, const monster &b)
{
return a.str < b.str;
}
bool compareByHeal(const monster &a, const monster &b)
{
return a.heal > b.heal ;
}
int z;
vector<int> order;
bool combat(monster mon)
{
z -= mon.str;
if (z <=0)
{
return false;
}
z += mon.heal;
order.push_back(mon.num);
return true;
}
int main()
{
int n;
cin>>n>>z;
vector<monster> profit;
vector<monster> nonprofit;
for (int i = 1; i <= n; ++i) // GET monsters
{
int d,a;
cin>>d>>a;
monster t;
t.num = i;
t.str = d;
t.heal= a;
if (t.heal >= t.str)//profitabel
{
profit.push_back(t);
}
else//non-profit
{
nonprofit.push_back(t);
}
}
//FIGHT profitables, by str ascending
sort(profit.begin(), profit.end(), compareByStr);
for(vector<monster>::iterator it=profit.begin(); it!=profit.end(); it++)
{
if(!combat(*it))
{
cout<<"NIE"<<endl;
return 0;
}
}
//FIGHT remaining, by heal descending
sort(nonprofit.begin(),nonprofit.end(),compareByHeal);
for(vector<monster>::iterator it=nonprofit.begin(); it!=nonprofit.end(); it++)
{
if(!combat(*it))
{
cout<<"NIE"<<endl;
return 0;
}
}
//wypis tak + kolejnosc
cout<<"TAK"<<endl;
for (vector<int>::iterator it=order.begin(); it != order.end(); ++it, cout<<" ")
{
cout<<*it;
}
cout<<endl;
}
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 | #include<iostream> #include<vector> #include<algorithm> using namespace std; struct _monster { int num; int str; int heal; }; typedef struct _monster monster; bool compareByStr(const monster &a, const monster &b) { return a.str < b.str; } bool compareByHeal(const monster &a, const monster &b) { return a.heal > b.heal ; } int z; vector<int> order; bool combat(monster mon) { z -= mon.str; if (z <=0) { return false; } z += mon.heal; order.push_back(mon.num); return true; } int main() { int n; cin>>n>>z; vector<monster> profit; vector<monster> nonprofit; for (int i = 1; i <= n; ++i) // GET monsters { int d,a; cin>>d>>a; monster t; t.num = i; t.str = d; t.heal= a; if (t.heal >= t.str)//profitabel { profit.push_back(t); } else//non-profit { nonprofit.push_back(t); } } //FIGHT profitables, by str ascending sort(profit.begin(), profit.end(), compareByStr); for(vector<monster>::iterator it=profit.begin(); it!=profit.end(); it++) { if(!combat(*it)) { cout<<"NIE"<<endl; return 0; } } //FIGHT remaining, by heal descending sort(nonprofit.begin(),nonprofit.end(),compareByHeal); for(vector<monster>::iterator it=nonprofit.begin(); it!=nonprofit.end(); it++) { if(!combat(*it)) { cout<<"NIE"<<endl; return 0; } } //wypis tak + kolejnosc cout<<"TAK"<<endl; for (vector<int>::iterator it=order.begin(); it != order.end(); ++it, cout<<" ") { cout<<*it; } cout<<endl; } |
English