[BOJ] 냉장고
Date:
[BOJ] 냉장고
Problem URL : 냉장고
#include <iostream>
#include <algorithm>
#include <queue>
#define p pair<int,int>
using namespace std;
int n;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
priority_queue<p, vector<p>, greater<p>> pq;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x += 270; y += 270;
pq.push({ x,y });
}
int ans = 1;
int pivot = pq.top().second;
pq.pop();
while (!pq.empty()) {
int x = pq.top().first;
int y = pq.top().second;
pq.pop();
if (x <= pivot) {
pivot = min(pivot, y);
}else {
ans += 1;
pivot = y;
}
}
cout << ans << endl;
}
댓글