Skip to content

Commit 7cddea0

Browse files
committed
14469 : 소가 길을 건너간 이유 3 solve
1 parent baeacb1 commit 7cddea0

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/week5/BOJ14469/BOJ14469_V1.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
struct cmp {
4+
bool operator() (pair<int, int> a, pair<int, int> b){
5+
if (a.first != b.first)
6+
return a.first > b.first;
7+
8+
return a.second > b.second;
9+
}
10+
};
11+
int main() {
12+
13+
ios_base::sync_with_stdio(false);
14+
cin.tie(nullptr);
15+
cout.tie(nullptr);
16+
17+
int n;
18+
cin >> n;
19+
20+
priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> pq;
21+
for (int i=0; i<n; i++) {
22+
int arrive, how;
23+
cin >> arrive >> how;
24+
pq.push({arrive, how});
25+
}
26+
27+
28+
29+
int t=1;
30+
while(!pq.empty()) {
31+
if (pq.top().first <= t) {
32+
t += pq.top().second;
33+
pq.pop();
34+
} else {
35+
t = pq.top().first + pq.top().second;
36+
pq.pop();
37+
}
38+
}
39+
40+
cout << t;
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)