mitkonikov

Kampanja Debug

Mar 11th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 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.     int i = 0;
  31.  
  32.     vector<bool> takens(c, false);
  33.  
  34.     for (i = 0; i < diff.size(); ++i) {
  35.  
  36.         // IF THE YOU CAN GO TO THAT CITY, GO THERE :D
  37.         if (n - diff[i].second >= 0) {
  38.             n -= diff[i].first;
  39.  
  40.             cout << "i: " << i << " => " << diff[i].first << ", " << diff[i].second << endl;
  41.             cout << "Taken " << diff[i].first << endl;
  42.             cout << "Current N: " << n << endl;
  43.             takens[i] = true;
  44.  
  45.             COUNT++;
  46.         }
  47.     }
  48.  
  49.     cout << "N left : " << n << endl;
  50.  
  51.     cout << "Next city : " << "i+1: " << i << " => " << diff[i].first << ", " << diff[i].second << endl;
  52.     cout << "Next city : " << "i+2: " << i+1 << " => " << diff[i+1].first << ", " << diff[i+1].second << endl;
  53.     cout << "Next city : " << "i+3: " << i+2 << " => " << diff[i+2].first << ", " << diff[i+2].second << endl;
  54.  
  55.     for (int t = 0; t < takens.size(); ++t) {
  56.         if (!takens[t]) {
  57.             cout << "not taken => t : " << t << ", costs : " << diff[t].second << endl;
  58.         }
  59.     }
  60.  
  61.     cout << COUNT << endl;
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment