-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworksch.cpp
More file actions
41 lines (37 loc) · 844 Bytes
/
Copy pathworksch.cpp
File metadata and controls
41 lines (37 loc) · 844 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
40
41
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
struct f {
long long d;
long long p;
} a[100005];
bool cmp(f A, f B) { return A.d < B.d; }
priority_queue<long long, vector<long long>, greater<long long> >
q; // 小根堆维护最小值
int main() {
long long n, i;
cin >> n;
for (i = 1; i <= n; i++) {
scanf("%lld%lld", &a[i].d, &a[i].p);
}
sort(a + 1, a + n + 1, cmp);
long long ans = 0;
for (i = 1; i <= n; i++) {
if (a[i].d <= (int)q.size()) { // 超过截止时间
if (q.top() < a[i].p) { // 后悔
ans += a[i].p - q.top();
q.pop();
q.push(a[i].p);
}
} else { // 直接加入队列
ans += a[i].p;
q.push(a[i].p);
}
}
cout << ans << endl;
return 0;
}