-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKattis Bank Queue.cpp
More file actions
38 lines (34 loc) · 904 Bytes
/
Kattis Bank Queue.cpp
File metadata and controls
38 lines (34 loc) · 904 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
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
int N = 0, T = 0, sum = 0;
cin >> N >> T;
vector<bool> spot(T, false);
vector<pair<int, int>> people;
while (N--) {
pair<int, int> ct(0, 0);
cin >> ct.first >> ct.second;
people.push_back(ct);
}
sort(people.begin(), people.end());
for (int i = people.size() - 1; i >= 0; --i) {
// highest value person to his last possible time spot or before that
for (int j = people[i].second; j >= 0; --j) {
if (spot[j] == false) {
spot[j] = true;
sum += people[i].first;
break;
}
}
}
cout << sum;
return 0;
}