
뭔가 그리드로 할 수 있을거같은디... 한번 시도는 해보자!
여기서도 제일 빨리 끝나는거가
1,4
그다음 4보다 큰 시작 중 제일 빨리 끝나는게 5,7
그다음 7보다 큰 시작 중 제일 빨리 끝나는게 8,11
그다음이 12 14 이케 4개니까
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool comp(pair<int, int>&a, pair<int, int>&b){
if(a.second == b.second) return a.first < b.first;
else return a.second < b.second;
} //일찍 끝나는 시간 순 정렬
int main(){
int N, st, ed;
cin >> N;
vector<pair<int,int>>v;
while(N--){
cin >> st >> ed;
v.push_back({st,ed});
}
sort(v.begin(), v.end(),comp);
int ans = 0; ed = 0;
for(auto x : v){
if(x.first >= ed){
ans++; ed = x.second;
}
}
cout << ans << "\n";
return 0;
}
성공 ★
'C++ 문제풀기 > 백준-프로그래머스' 카테고리의 다른 글
| 프로그래머스 | 합승 택시 요금 (0) | 2025.11.05 |
|---|---|
| 백준 | 2579. 계단오르기 (0) | 2025.11.04 |
| 백준 | 1920. 수 찾기 (0) | 2025.10.31 |
| 프로그래머스 | 귤 고르기 (0) | 2025.10.28 |
| 프로그래머스 | 구명보트 (0) | 2025.10.28 |