#include <cstdio> #include <vector> #include <algorithm> #include <utility> using namespace std; int main(){ int i,ile,pot,elix; long long moc; vector <pair <int,int> > ala; vector < pair <int, pair<int,int> > > dodaj, ujmij; scanf("%d %Ld",&ile,&moc); for(i=1;i<=ile;i++){ scanf("%d%d",&pot,&elix); if(elix >= pot) dodaj.push_back(make_pair(pot, make_pair(elix - pot,i))); else ujmij.push_back(make_pair(pot,make_pair(elix - pot,i))); } //sortowanie sort(dodaj.begin(),dodaj.end()); sort(ujmij.begin(),ujmij.end()); for(i=0;i<dodaj.size();i++){ if(moc > dodaj[i].first) moc += dodaj[i].second.first; else {moc=-1;break;} } for (i=ujmij.size()-1;i>=0;i--){ if(moc > ujmij[i].first) moc += ujmij[i].second.first; else {moc=-1;break;} //printf("moc=%d\n",moc); } if(moc<1) puts("NIE"); else { puts("TAK"); for(i=0;i<dodaj.size();i++) printf("%d ",dodaj[i].second.second); for(i=ujmij.size()-1;i>=0;i--) printf("%d ",ujmij[i].second.second); puts(""); } 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 | #include <cstdio> #include <vector> #include <algorithm> #include <utility> using namespace std; int main(){ int i,ile,pot,elix; long long moc; vector <pair <int,int> > ala; vector < pair <int, pair<int,int> > > dodaj, ujmij; scanf("%d %Ld",&ile,&moc); for(i=1;i<=ile;i++){ scanf("%d%d",&pot,&elix); if(elix >= pot) dodaj.push_back(make_pair(pot, make_pair(elix - pot,i))); else ujmij.push_back(make_pair(pot,make_pair(elix - pot,i))); } //sortowanie sort(dodaj.begin(),dodaj.end()); sort(ujmij.begin(),ujmij.end()); for(i=0;i<dodaj.size();i++){ if(moc > dodaj[i].first) moc += dodaj[i].second.first; else {moc=-1;break;} } for (i=ujmij.size()-1;i>=0;i--){ if(moc > ujmij[i].first) moc += ujmij[i].second.first; else {moc=-1;break;} //printf("moc=%d\n",moc); } if(moc<1) puts("NIE"); else { puts("TAK"); for(i=0;i<dodaj.size();i++) printf("%d ",dodaj[i].second.second); for(i=ujmij.size()-1;i>=0;i--) printf("%d ",ujmij[i].second.second); puts(""); } return 0; } |