Advertisement
Gashish

misos boxs 2

Jan 24th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <string>
  7. #include <map>
  8.  
  9. using namespace std;
  10.  
  11. struct box {
  12.     int first;
  13.     int second;
  14.     int index;
  15. };
  16. bool comp(box a, box b) {
  17.     if (a.second > b.second) return true;
  18.     if (a.second < b.second) return false;
  19.     if (a.first > b.first) return true;
  20.     return false;
  21. }
  22. int main() {
  23.     int n, mass = 0;
  24.     cin >> n;
  25.    
  26.     vector <box> v(n);
  27.     for (int i = 0; i < n; ++i) {
  28.         cin >> v[i].first >> v[i].second;
  29.         v[i].index = i + 1;
  30.     }
  31.     sort(v.begin(), v.end(), comp);
  32.     for (int i = n - 1; i >= 0; --i) {
  33.         if (v[i].first < mass) {
  34.             cout << "-1";
  35.             return 0;
  36.         }
  37.         mass += v[i].second;
  38.     }
  39.     for (int i = 0; i < n; i++) {
  40.         cout << v[i].index << "\n";
  41.     }
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement