Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool sorting(pair<int, int> a, pair<int, int> b) {
- if (a.first == b.first) {
- if (a.second > b.second) return true;
- else return false;
- } else if (a.first < b.first)
- return true;
- return false;
- }
- int main()
- {
- int n, c;
- cin >> n >> c;
- vector< pair<int, int> > diff;
- for (int i = 0; i < c; ++i) {
- int p, r;
- cin >> p >> r;
- diff.push_back(make_pair(p - r, p));
- }
- sort(diff.begin(), diff.end(), sorting);
- int COUNT = 0;
- for (int i = 0; i < diff.size(); ++i) {
- // IF THE YOU CAN GO TO THAT CITY, GO THERE :D
- if (n - diff[i].second >= 0) {
- n -= diff[i].first;
- COUNT++;
- }
- }
- cout << COUNT << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment