Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <map>
- using namespace std;
- struct box {
- int first;
- int second;
- int index;
- };
- bool comp(box a, box b) {
- if (a.second > b.second) return true;
- if (a.second < b.second) return false;
- if (a.first > b.first) return true;
- return false;
- }
- int main() {
- int n, mass = 0;
- cin >> n;
- vector <box> v(n);
- for (int i = 0; i < n; ++i) {
- cin >> v[i].first >> v[i].second;
- v[i].index = i + 1;
- }
- sort(v.begin(), v.end(), comp);
- for (int i = n - 1; i >= 0; --i) {
- if (v[i].first < mass) {
- cout << "-1";
- return 0;
- }
- mass += v[i].second;
- }
- for (int i = 0; i < n; i++) {
- cout << v[i].index << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement