-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKoi2019-1 A.cpp
More file actions
68 lines (54 loc) · 1.12 KB
/
Koi2019-1 A.cpp
File metadata and controls
68 lines (54 loc) · 1.12 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
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
#define LL long long
using namespace std;
struct mall{ int time, id, idx; };
struct cmp{
bool operator()(mall x, mall y){
if(x.time == y.time) return x.idx > y.idx;
else return x.time > y.time;
}
};
bool _cmp(mall x, mall y){
if(x.time == y.time) return x.idx > y.idx;
else return x.time < y.time;
}
int n, k, cnt = 1;
LL int sum = 0;
priority_queue<mall, vector<mall>, cmp>pQ;
vector<mall>ans;
int main()
{
scanf("%d %d", &n, &k);
for(int i = 1; i <= k; i++){
pQ.push({0, 0, i});
}
for(int i = 1; i <= n; i++){
int a, b;
scanf("%d %d", &a, &b);
int TIME = pQ.top().time;
int ID = pQ.top().id;
int IDX = pQ.top().idx;
pQ.pop();
if(ID != 0){
ans.push_back({TIME, ID, IDX});
}
pQ.push({TIME+b, a, IDX});
}
while(!pQ.empty()){
int TIME = pQ.top().time;
int ID = pQ.top().id;
int IDX = pQ.top().idx;
if(ID != 0){
ans.push_back({TIME, ID, IDX});
}
pQ.pop();
}
sort(ans.begin(), ans.end(), _cmp);
for(int i = 0; i < ans.size(); i++){
sum += (LL int) ans[i].id * (i+1);
}
printf("%lld", sum);
}