#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstdio>
using namespace std;
struct potwory
{
int eliksir;
int hppotwora;
int kolejwpis;
int kolejpraw;
};
potwory tab [100000];
//int kolej [100000];
bool cmp(potwory i, potwory j)
{
return i.hppotwora > j.hppotwora;
}
bool cmp1(potwory i, potwory j)
{
return i.kolejpraw < j.kolejpraw;
}
int main()
{ ios_base::sync_with_stdio(0);
int potwory, zdrowiepocz, robocza;
int licznik = 0;
cin >> potwory;
cin >> zdrowiepocz;
int b = 0;
int potwory1 = potwory;
for (int i = 0; i<potwory1; i++)
{
cin >> tab[i].hppotwora;
cin >> tab[i].eliksir;
tab[i].kolejwpis = i + 1;
}
for (int i = 0; i<potwory1; i++)
{
for (int i = 0; i<potwory1; i++)
{
if (tab[i].eliksir >= tab[i].hppotwora && tab[i].hppotwora < zdrowiepocz )
{
b++;
tab[i].kolejpraw = b;
zdrowiepocz = zdrowiepocz + (tab[i].eliksir - tab[i].hppotwora);
}
}
}
sort(tab, tab + potwory1, cmp);
for (int i = 0; i<potwory1; i++)
{
if (tab[i].kolejpraw==0)
{
if (zdrowiepocz > tab[i].hppotwora)
{
zdrowiepocz = zdrowiepocz - (tab[i].hppotwora - tab[i].eliksir);
b++;
tab[i].kolejpraw = b;
}
else
{
cout << "NIE";
return 0;
}
}
}
sort(tab, tab + potwory1, cmp1);
cout << "TAK" << endl;
for (int i = 0; i<potwory1; i++)
{
cout << tab[i].kolejwpis << " ";
}
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 | #include <iostream> #include <math.h> #include <algorithm> #include <cstdio> using namespace std; struct potwory { int eliksir; int hppotwora; int kolejwpis; int kolejpraw; }; potwory tab [100000]; //int kolej [100000]; bool cmp(potwory i, potwory j) { return i.hppotwora > j.hppotwora; } bool cmp1(potwory i, potwory j) { return i.kolejpraw < j.kolejpraw; } int main() { ios_base::sync_with_stdio(0); int potwory, zdrowiepocz, robocza; int licznik = 0; cin >> potwory; cin >> zdrowiepocz; int b = 0; int potwory1 = potwory; for (int i = 0; i<potwory1; i++) { cin >> tab[i].hppotwora; cin >> tab[i].eliksir; tab[i].kolejwpis = i + 1; } for (int i = 0; i<potwory1; i++) { for (int i = 0; i<potwory1; i++) { if (tab[i].eliksir >= tab[i].hppotwora && tab[i].hppotwora < zdrowiepocz ) { b++; tab[i].kolejpraw = b; zdrowiepocz = zdrowiepocz + (tab[i].eliksir - tab[i].hppotwora); } } } sort(tab, tab + potwory1, cmp); for (int i = 0; i<potwory1; i++) { if (tab[i].kolejpraw==0) { if (zdrowiepocz > tab[i].hppotwora) { zdrowiepocz = zdrowiepocz - (tab[i].hppotwora - tab[i].eliksir); b++; tab[i].kolejpraw = b; } else { cout << "NIE"; return 0; } } } sort(tab, tab + potwory1, cmp1); cout << "TAK" << endl; for (int i = 0; i<potwory1; i++) { cout << tab[i].kolejwpis << " "; } return 0; } |
polski