Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions fnhid/PriorityQueue/1374.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

struct Lecture
{
long long start, end;
};

int max(int a, int b)
{
return a > b ? a : b;
}
Comment on lines +11 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<algorithm> 라이브러리λ₯Ό μ‚¬μš©ν•œ 경우,
두 인자λ₯Ό λΉ„κ΅ν•˜μ—¬ μ΅œλŒ“κ°’κ³Ό μ΅œμ†Ÿκ°’μ„ λ°˜ν™˜ν•˜λŠ” max() 와 min() ν•¨μˆ˜λ₯Ό μ œκ³΅ν•΄μ£ΌκΈ°λ•Œλ¬Έμ—
μ»€μŠ€ν…€ ν•¨μˆ˜ μ„ μ–Έ 없이 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. νŽΈλ¦¬ν•΄μš© γ…Žγ…Ž

참고둜 max()ν•¨μˆ˜μ˜ λ‚΄λΆ€ μ½”λ“œ ꡬ쑰가 μœ ν˜„λ‹˜μ΄ μ„ μ–Έν•˜μ‹  μ»€μŠ€ν…€ ν•¨μˆ˜μ™€ λ™μΌν•©λ‹ˆλ‹€ γ…‹γ…‹γ…‹


using namespace std;

int main()
{
int n, id, answer=0;
priority_queue<long long, vector<long long>, greater<long long>> pq;


cin >> n;
vector<Lecture> v(n);
for (int i=0;i<n;i++)
{
cin >> id >> v[id-1].start >> v[id-1].end;
}

sort(v.begin(), v.end(), [](const Lecture& a, const Lecture& b)
{
return a.start < b.start;
});

for (Lecture& l : v)
{

while (!pq.empty() && pq.top() <= l.start)
pq.pop();
pq.push(l.end);
answer = max(answer, (int)pq.size());
}


cout << answer;

}