Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #include <vector>
- #include <queue>
- using namespace std;
- struct pereche
- {
- int cost, timp;
- };
- pereche v[10001];
- class cmp
- {
- public:
- bool operator () (const pereche &a, const pereche &b) const
- {
- return a.timp < b.timp;
- }
- };
- class cmp2
- {
- public:
- bool operator () (const int &a, const int &b) const
- {
- return a<b;
- }
- };
- priority_queue<int, vector<int>, cmp2> Q;
- int main()
- {
- ifstream fin ("credite.in");
- ofstream fout ("credite.out");
- int n, answer = 0;
- fin >> n;
- for (int i = 1; i<=n; ++i)
- fin >> v[i].cost >> v[i].timp;
- sort(v+1, v+n+1, cmp());
- int indice = n;
- for (int time = 10000; time>=1; --time)
- {
- while (indice && v[indice].timp >= time)
- {
- Q.push(v[indice].cost);
- --indice;
- }
- if (Q.size())
- {
- answer+=Q.top();
- Q.pop();
- }
- }
- fout << answer;
- return 0;
- }
Add Comment
Please, Sign In to add comment