-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzad7jc.cpp
51 lines (40 loc) · 1006 Bytes
/
zad7jc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<algorithm>
typedef struct _para{
int a;
int b;
} para;
bool greater(para a, para b){
return a.a < b.a;
}
int rejs(int k, const std::vector<int> start, const std::vector<int> end){
std::vector<para> v;
int maks = 0;
for(size_t i = 0; i < start.size(); i++){
para temp;
temp.a = start[i];
temp.b = end[i];
v.push_back(temp);
}
std::sort(v.begin(), v.end(), greater);
std::priority_queue<int> pq;
for(size_t i = 0; i < v.size(); i++){
while(!pq.empty() && abs(pq.top()) <= v[i].a){
pq.pop();
}
pq.push(-v[i].b);
while(pq.size() > (size_t)k){
pq.pop();
}
if(pq.size() == (size_t)k)
maks = std::max((-pq.top() - v[i].a + 1), maks);
}
return maks;
}
int main(){
printf("%i\n", rejs(2, {12, 48, 28, 50, 0, 25}, {36, 100, 70, 80, 69, 30}));
return 0;
}