#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<vector>
struct zysk
{
int zabiera;
int oddaje;
int numer;
bool pokon;
int bilans;
};
bool porownaj(zysk a, zysk b)
{
if (a.bilans == 0 && b.bilans == 0) return true;
if (a.bilans > 0 && b.bilans < 0) return true;
if (a.bilans < 0 && b.bilans > 0) return false;
if (a.zabiera == b.zabiera)
{
if(a.oddaje > b.oddaje) return true;
return false;
}
if ((a.bilans < 0) && (b.bilans < 0))
{
if(a.zabiera > b.zabiera) return true;
return false;
}
if (a.bilans > b.bilans) return true;
return false;
}
using namespace std;
int main(int argc, char *argv[])
{
bool debug = false;
if (argc > 1) debug = true;
int ilepotwor = 0, zycie = 0;
scanf("%d %d", &ilepotwor, &zycie);
int zostalo = ilepotwor;
vector <int>kolejnosc;
zysk tab[ilepotwor];
for (int i = 0;i < ilepotwor; i++)
{
tab[i].numer = i + 1;
scanf("%d", &tab[i].zabiera);
scanf("%d", &tab[i].oddaje);
tab[i].pokon = false;
tab[i].bilans = tab[i].oddaje - tab[i].zabiera;
}
sort(tab, tab + ilepotwor, porownaj);
if (debug == true)
{
for (int i = 0;i < ilepotwor; i++)
{
printf("%d ", tab[i].zabiera);
printf("%d", tab[i].oddaje);
printf("z bilansem %d\n", tab[i].bilans);
}
}
bool czujka = true;
while (czujka == true)
{
czujka = false;
for (int i = 0; i < ilepotwor; i ++)
{
if (tab[i].pokon == false)
if (tab[i].zabiera < zycie)
{
tab[i].pokon = true;
czujka = true;
zycie = (zycie - tab[i].zabiera) + tab[i].oddaje;
zostalo --;
kolejnosc.push_back(tab[i].numer);
break;
}
}
}
if (zostalo > 0) puts("NIE");
else
{
puts("TAK");
printf("%d", kolejnosc[0]);
for(int i = 1; i < ilepotwor;i++) printf(" %d", kolejnosc[i]);
printf("\n");
}
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 81 82 83 84 85 86 87 88 89 90 91 92 | #include <iostream> #include <stdio.h> #include<algorithm> #include<vector> struct zysk { int zabiera; int oddaje; int numer; bool pokon; int bilans; }; bool porownaj(zysk a, zysk b) { if (a.bilans == 0 && b.bilans == 0) return true; if (a.bilans > 0 && b.bilans < 0) return true; if (a.bilans < 0 && b.bilans > 0) return false; if (a.zabiera == b.zabiera) { if(a.oddaje > b.oddaje) return true; return false; } if ((a.bilans < 0) && (b.bilans < 0)) { if(a.zabiera > b.zabiera) return true; return false; } if (a.bilans > b.bilans) return true; return false; } using namespace std; int main(int argc, char *argv[]) { bool debug = false; if (argc > 1) debug = true; int ilepotwor = 0, zycie = 0; scanf("%d %d", &ilepotwor, &zycie); int zostalo = ilepotwor; vector <int>kolejnosc; zysk tab[ilepotwor]; for (int i = 0;i < ilepotwor; i++) { tab[i].numer = i + 1; scanf("%d", &tab[i].zabiera); scanf("%d", &tab[i].oddaje); tab[i].pokon = false; tab[i].bilans = tab[i].oddaje - tab[i].zabiera; } sort(tab, tab + ilepotwor, porownaj); if (debug == true) { for (int i = 0;i < ilepotwor; i++) { printf("%d ", tab[i].zabiera); printf("%d", tab[i].oddaje); printf("z bilansem %d\n", tab[i].bilans); } } bool czujka = true; while (czujka == true) { czujka = false; for (int i = 0; i < ilepotwor; i ++) { if (tab[i].pokon == false) if (tab[i].zabiera < zycie) { tab[i].pokon = true; czujka = true; zycie = (zycie - tab[i].zabiera) + tab[i].oddaje; zostalo --; kolejnosc.push_back(tab[i].numer); break; } } } if (zostalo > 0) puts("NIE"); else { puts("TAK"); printf("%d", kolejnosc[0]); for(int i = 1; i < ilepotwor;i++) printf(" %d", kolejnosc[i]); printf("\n"); } return 0; } |
English