Skip to content

Commit

Permalink
회의실 배정
Browse files Browse the repository at this point in the history
  • Loading branch information
yewon-yw authored May 23, 2022
1 parent 3789c42 commit d6acf81
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions greedy_algorithm/1931.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<pair<int,int>> arr;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, s, e, cnt = 1;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s >> e;
arr.push_back(make_pair(e, s));
}
sort(arr.begin(), arr.end());
e = arr.front().first;
for (int i = 1; i < n; i++) {
if (e <= arr.at(i).second) {
cnt++;
e = arr.at(i).first;
}
}
cout << cnt << "\n";
}

0 comments on commit d6acf81

Please sign in to comment.