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
| #include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct PQ {
int a, b;
};
priority_queue<PQ> pq;
bool operator<(PQ a, PQ b) {
return a.b > b.b;
}
struct PQ2 {
int a, b;
};
priority_queue<PQ2> pq2;
bool operator<(PQ2 a, PQ2 b) {
if (a.a == b.a)return a.b > b.b;
return a.a > b.a;
}
int solution(vector<vector<int>> jobs) {
int answer = 0;
int now_time = 0;
int cnt = 0;
int all_time = 0;
int _size = jobs.size();
for (int i = 0; i < _size; ++i) {
pq2.push({ jobs[i][0], jobs[i][1] });
}
while (!_size == 0) {
_size--;
int q_size = pq2.size();
for (int i = 0; i < q_size; ++i) {
if (i == 0 && pq2.top().a > now_time)
now_time = pq2.top().a;
if (pq2.top().a <= now_time) {
pq.push({ pq2.top().a, pq2.top().b });
pq2.pop();
}
else break;
}
while (!pq.empty()) {
cnt++;
all_time += (pq.top().b + now_time - pq.top().a);
now_time += pq.top().b;
pq.pop();
if (pq.size() > 0 && pq2.size() > 0 && pq2.top().a <= now_time)break;
}
}
answer = all_time / cnt;
return answer;
}
|