Skip to content

Commit 0eae05f

Browse files
multiset with upper bound (room allotment with k number)
1 parent 1c35281 commit 0eae05f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// link : https://cses.fi/problemset/task/1632/
2+
3+
#include<bits/stdc++.h>
4+
#define int long long
5+
using namespace std;
6+
#define MOD 1000000007
7+
8+
signed main() {
9+
ios_base::sync_with_stdio(0);
10+
cin.tie(0);
11+
int n,k;
12+
cin>>n>>k;
13+
vector<pair<int,int>>vec(n);
14+
for(auto &it:vec){
15+
cin>>it.second>>it.first;
16+
}
17+
sort(vec.begin(),vec.end());
18+
multiset<int>mp;
19+
int cnt=0;
20+
for(auto it:vec){
21+
auto up=mp.upper_bound(it.second);
22+
if(up!=mp.begin()){
23+
up--;
24+
mp.erase(up);
25+
}
26+
if(size(mp)<k){
27+
mp.insert(it.first);
28+
cnt++;
29+
}
30+
}
31+
cout<<cnt<<endl;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)