a53

Credite

a53
Mar 13th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <queue>
  5. using namespace std;
  6. struct pereche
  7. {
  8. int cost, timp;
  9. };
  10. pereche v[10001];
  11. class cmp
  12. {
  13. public:
  14. bool operator () (const pereche &a, const pereche &b) const
  15. {
  16. return a.timp < b.timp;
  17. }
  18. };
  19. class cmp2
  20. {
  21. public:
  22. bool operator () (const int &a, const int &b) const
  23. {
  24. return a<b;
  25. }
  26. };
  27. priority_queue<int, vector<int>, cmp2> Q;
  28. int main()
  29. {
  30. ifstream fin ("credite.in");
  31. ofstream fout ("credite.out");
  32. int n, answer = 0;
  33. fin >> n;
  34. for (int i = 1; i<=n; ++i)
  35. fin >> v[i].cost >> v[i].timp;
  36. sort(v+1, v+n+1, cmp());
  37. int indice = n;
  38. for (int time = 10000; time>=1; --time)
  39. {
  40. while (indice && v[indice].timp >= time)
  41. {
  42. Q.push(v[indice].cost);
  43. --indice;
  44. }
  45. if (Q.size())
  46. {
  47. answer+=Q.top();
  48. Q.pop();
  49. }
  50. }
  51. fout << answer;
  52. return 0;
  53. }
Add Comment
Please, Sign In to add comment