Created
April 19, 2020 02:23
-
-
Save niklasjang/adb2cc3df30daf4cb5b4b457a2837528 to your computer and use it in GitHub Desktop.
[PS][그리디]/[BOJ][1931][회의실 배정]
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 <algorithm> | |
#include <vector> | |
using namespace std; | |
int n; | |
vector<pair<int, int > > v; | |
bool compare(pair<int, int> a, pair<int, int> b) { | |
if(a.second != b.second) return a.second < b.second; | |
else return a.first < b.first; | |
} | |
int main(void) { | |
cin >> n; | |
pair<int, int> t; | |
for (int i = 0; i < n; i++) { | |
cin >> t.first >> t.second; | |
v.push_back(t); | |
} | |
sort(v.begin(), v.end(), compare); | |
int ans = 1; | |
t = v[0]; | |
for (int i = 1; i < v.size(); i++) { | |
if (t.second <= v[i].first) { | |
ans++; | |
t = v[i]; | |
} | |
} | |
cout << ans << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment