forked from shunr/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcco17p5.cpp
More file actions
86 lines (73 loc) · 1.57 KB
/
cco17p5.cpp
File metadata and controls
86 lines (73 loc) · 1.57 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
#define need first
#define cost second
using namespace std;
typedef pair<int, int> ip;
array<ip, 200005> dudes;
priority_queue<int, vector<int>, greater<int>> buy;
int n;
struct comp
{
bool operator() (const ip& a, const ip& b) const
{
if (a.first == b.first)
return a.second < b.second;
else
return a.first > b.first;
}
};
int main() {
scanf("%i", &n);
int a, b;
int s = 0;
int c = 0;
for (int i = 0; i < n; i++) {
scanf("%i %i", &dudes[i].need, &dudes[i].cost);
}
sort(dudes.begin(), dudes.end(), comp());
for (int i = 0; i < n; i++) {
//printf("%i %i | ", dudes[i].need, dudes[i].cost);
}
for (int i = 0; i < n; i++) {
int need_ = dudes[i].need;
int cost_ = dudes[i].cost;
int diff = need_ - (n-i-1+s);
buy.push(cost_);
if (diff <= 0) {
continue;
} else {
for (int j = 0; j < diff; j++) {
c += buy.top();
buy.pop();
}
s += diff;
}
}
printf("%i", c);
}
/*
from heapq import *
from collections import deque
n = int(input())
dudes = []
buy = []
for _ in range(n):
a, b = (int(i) for i in input().split())
dudes.append((a, -b))
dudes.sort(reverse=True)
s = 0
c = 0
#print(dudes)
for i in range(n):
need, cost = (dudes[i][0], -dudes[i][1])
diff = need - (n-i-1+s)
#print(need,cost,diff)
heappush(buy, cost)
if diff <= 0:
continue
else:
for j in range(diff):
#print("Buying", s+s)
c += heappop(buy)
s+=diff
print(c)*/