문제 링크입니다: https://www.acmicpc.net/problem/14469
14469번: 소가 길을 건너간 이유 3
이웃 농장의 소가 길을 마구잡이로 건너는 것에 진절머리가 난 존은 극단의 결정을 내린다. 농장 둘레에 매우 큰 울타리를 짓는 것이다. 이렇게 하면 근처 농장 출신의 소가 들어올 일이 거의 없
www.acmicpc.net
시간을 기준으로 오름차순, 시간이 동일하다면 대기 시간을 기준으로 오름차순 정렬을 하면 쉽게 풀 수 있는 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
vector<pair<int, int>> v(N); | |
for (int i = 0; i < N; i++) | |
{ | |
int a, b; | |
cin >> a >> b; | |
v.push_back({ a, b }); | |
} | |
sort(v.begin(), v.end()); | |
int result = 0; | |
for (pair<int, int> p : v) | |
{ | |
if (result < p.first) | |
{ | |
result = p.first + p.second; | |
} | |
else | |
{ | |
result += p.second; | |
} | |
} | |
cout << result << "\n"; | |
return 0; | |
} |

개발환경:Visual Studio 2022
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2776번 암기왕 (0) | 2024.04.20 |
---|---|
백준 13144번 List of Unique Numbers (0) | 2024.04.08 |
백준 2109번 순회강연 (0) | 2024.04.06 |
백준 2170번 선 긋기 (0) | 2024.04.03 |
백준 14729번 칠무해 (0) | 2024.04.03 |