Skip to content

Commit ea2be3b

Browse files
authored
Merge pull request #65 from solid-connection/whqtker
[Week09] BOJ 23088: Aging
2 parents 6199af3 + 18b68ce commit ea2be3b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
#include <tuple>
3+
#include <queue>
4+
#include <vector>
5+
6+
using namespace std;
7+
typedef tuple<int,int,int> tii;
8+
9+
int main() {
10+
cin.tie(0);
11+
ios::sync_with_stdio(0);
12+
13+
int n;
14+
cin>>n;
15+
16+
// 실행 순위: 우선순위 높음 > 실행 시간 짧음 > 먼저 등장
17+
vector<tii> v; // 실행 요청 시점, 초기 우선순위, 실행 시간
18+
for (int i=0;i<n;i++) {
19+
int a,b,c; // 실행 요청 시점, 초기 우선순위, 실행 시간
20+
cin>>a>>b>>c;
21+
v.push_back({a,b,c});
22+
}
23+
24+
int curTime=0;
25+
int idx=0;
26+
priority_queue<tii> pq; // 보정된 우선순위, -실행시간, -등장 번호
27+
while (idx<n||!pq.empty()) {
28+
// 현재 시간까지 도착한 작업 pq에 삽입
29+
while (idx<n&&get<0>(v[idx])<=curTime) {
30+
pq.push({get<1>(v[idx])-get<0>(v[idx]),-get<2>(v[idx]),-(idx+1)});
31+
idx++;
32+
}
33+
34+
// 처리할 작업 없는 경우
35+
if (pq.empty()) {
36+
curTime=get<0>(v[idx]);
37+
}
38+
else {
39+
int num=-get<2>(pq.top());
40+
cout<<num<<" ";
41+
curTime-=get<1>(pq.top());
42+
pq.pop();
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)