// Michał Wiatrowski
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
// Wczytywanie danych
int n, z;
cin >> n >> z;
vector<pair<int, int> > potwory(n);
for (int p = 0; p < n; ++p)
cin >> potwory[p].first >> potwory[p].second;
vector<int> kolejnosc(n);
for (int i = 0; i < n; ++i)
kolejnosc[i] = i;
// Sortowanie
sort(kolejnosc.begin(), kolejnosc.end(), [&](const int& lnr, const int& rnr) {
pair<int, int>& lhs = potwory[lnr];
pair<int, int>& rhs = potwory[rnr];
int lhs_balance = lhs.second - lhs.first;
int rhs_balance = rhs.second - rhs.first;
if (lhs_balance > 0 && rhs_balance > 0) {
if (lhs.first < rhs.first)
return true;
else
return false;
} else if (lhs_balance == 0 && rhs_balance == 0) {
return true;
} else if (lhs_balance < 0 && rhs_balance < 0) {
if (lhs.second > rhs.second)
return true;
else
return false;
} else {
if (lhs_balance > rhs_balance)
return true;
else
return false;
}
});
// Symulacja
bool da_sie = true;
for (int i = 0; i < n; ++i) {
int p = kolejnosc[i];
z -= potwory[p].first;
if (z <= 0) {
da_sie = false;
break;
}
z += potwory[p].second;
}
// Wypisywanie wyniku
if (da_sie) {
cout << "TAK" << endl;
for (int i = 0; i < n; ++i)
cout << kolejnosc[i] + 1 << " ";
cout << endl;
} else {
cout << "NIE" << endl;
}
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 | // Michał Wiatrowski #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); // Wczytywanie danych int n, z; cin >> n >> z; vector<pair<int, int> > potwory(n); for (int p = 0; p < n; ++p) cin >> potwory[p].first >> potwory[p].second; vector<int> kolejnosc(n); for (int i = 0; i < n; ++i) kolejnosc[i] = i; // Sortowanie sort(kolejnosc.begin(), kolejnosc.end(), [&](const int& lnr, const int& rnr) { pair<int, int>& lhs = potwory[lnr]; pair<int, int>& rhs = potwory[rnr]; int lhs_balance = lhs.second - lhs.first; int rhs_balance = rhs.second - rhs.first; if (lhs_balance > 0 && rhs_balance > 0) { if (lhs.first < rhs.first) return true; else return false; } else if (lhs_balance == 0 && rhs_balance == 0) { return true; } else if (lhs_balance < 0 && rhs_balance < 0) { if (lhs.second > rhs.second) return true; else return false; } else { if (lhs_balance > rhs_balance) return true; else return false; } }); // Symulacja bool da_sie = true; for (int i = 0; i < n; ++i) { int p = kolejnosc[i]; z -= potwory[p].first; if (z <= 0) { da_sie = false; break; } z += potwory[p].second; } // Wypisywanie wyniku if (da_sie) { cout << "TAK" << endl; for (int i = 0; i < n; ++i) cout << kolejnosc[i] + 1 << " "; cout << endl; } else { cout << "NIE" << endl; } return 0; } |
English