-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathbank.cc
More file actions
39 lines (36 loc) · 705 Bytes
/
Copy pathbank.cc
File metadata and controls
39 lines (36 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// https://open.kattis.com/problems/bank
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef multiset<int, greater<int>> si;
typedef vector<si> vsi;
int main() {
int n, t;
cin >> n >> t;
vsi v(t);
for (int i = 0; i < n; i++) {
int ci, ti;
cin >> ci >> ti;
v[ti].insert(ci);
}
ll sum = 0;
for (int i = t - 1; i >= 0; i--) {
int m = 0;
int k = -1;
for (int j = i; j < t; j++) {
auto it = v[j].begin();
if (it == v[j].end()) continue;
if (*it > m) {
k = j;
m = *it;
}
}
if (k >= 0) {
sum += m;
v[k].erase(v[k].begin());
}
}
cout << sum << endl;
}