코드
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
bool compare(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second < b.second) {
return true;
} else if (a.second > b.second) {
return false;
} else {
return (a.first < b.first);
}
}
int N, s, e;
vector<pair<int, int>> meetings;
int lastEndTime = 0, answer = 0;
int main()
{
cin >> N;
for (int n = 0; n < N; n++) {
cin >> s >> e;
meetings.push_back({ s, e });
}
sort(meetings.begin(), meetings.end(), compare);
for (int i = 0; i < meetings.size(); i++) {
if (lastEndTime <= meetings[i].first) {
lastEndTime = meetings[i].second;
answer++;
}
}
cout << answer << '\n';
return 0;
}
결과
결과 | 메모리 | 시간 |
맞았습니다!! | 3572 KB | 96 ms |