mitkonikov

Kampanja Unfinished

Mar 11th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool sorting(pair<int, int> a, pair<int, int> b) {
  6.     if (a.first == b.first) {
  7.         if (a.second > b.second) return true;
  8.         else return false;
  9.     } else if (a.first < b.first)
  10.         return true;
  11.     return false;
  12. }
  13.  
  14. int main()
  15. {
  16.     int n, c;
  17.     cin >> n >> c;
  18.  
  19.     vector<  pair<int, int>  > diff;
  20.     for (int i = 0; i < c; ++i) {
  21.         int p, r;
  22.         cin >> p >> r;
  23.  
  24.         diff.push_back(make_pair(p - r, p));
  25.     }
  26.  
  27.     sort(diff.begin(), diff.end(), sorting);
  28.  
  29.     int COUNT = 0;
  30.     for (int i = 0; i < diff.size(); ++i) {
  31.  
  32.         // IF THE YOU CAN GO TO THAT CITY, GO THERE :D
  33.         if (n - diff[i].second >= 0) {
  34.             n -= diff[i].first;
  35.  
  36.             COUNT++;
  37.         }
  38.     }
  39.  
  40.     cout << COUNT << endl;
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment