#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,m,b[100005];
multiset<ll>st;
pair<ll,ll>a[100005];
bool check(ll x){
vector<ll>v;
for(int i=m-x+1; i<=m; i++)v.pb(b[i]);
ll lastval = 0;
ll ind = 1;
st.clear();
for(int i=0; i<v.size(); i++){
while(a[ind].f <= v[i] && ind <= n){
st.insert(a[ind].s);
ind++;
}
if(st.size())
while((*st.begin()) < lastval){
st.erase(st.begin());
if(st.empty())return 0;
}
if(st.empty())return 0;
lastval = (*st.begin());
st.erase(st.begin());
}
return 1;
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i=1; i<=n; i++)cin >> a[i].f >> a[i].s;
sort(a + 1,a + n + 1);
for(int i=1; i<=m; i++)cin >> b[i];
sort(b + 1,b + m + 1);
ll l = 1,r = min(n , m),mid,ans = 0;
while(r >= l){
mid = (l + r) / 2;
if(check(mid)){
l = mid + 1;
ans = mid;
}
else r = mid - 1;
}
cout << ans << endl;
return 0;
}
Compilation message
joi2019_ho_t2.cpp: In function 'bool check(long long int)':
joi2019_ho_t2.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<v.size(); i++){
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
448 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
512 KB |
Output is correct |
25 |
Correct |
4 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
380 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
640 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
448 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
512 KB |
Output is correct |
25 |
Correct |
4 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
380 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
35 |
Correct |
2 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
640 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
202 ms |
9524 KB |
Output is correct |
39 |
Correct |
196 ms |
9452 KB |
Output is correct |
40 |
Correct |
231 ms |
9708 KB |
Output is correct |
41 |
Correct |
203 ms |
9584 KB |
Output is correct |
42 |
Correct |
54 ms |
6136 KB |
Output is correct |
43 |
Correct |
53 ms |
6264 KB |
Output is correct |
44 |
Correct |
263 ms |
8456 KB |
Output is correct |
45 |
Correct |
681 ms |
11440 KB |
Output is correct |
46 |
Correct |
591 ms |
11432 KB |
Output is correct |
47 |
Correct |
868 ms |
10260 KB |
Output is correct |
48 |
Correct |
654 ms |
10392 KB |
Output is correct |
49 |
Correct |
525 ms |
9152 KB |
Output is correct |
50 |
Correct |
414 ms |
9120 KB |
Output is correct |
51 |
Correct |
52 ms |
6264 KB |
Output is correct |
52 |
Correct |
52 ms |
6236 KB |
Output is correct |
53 |
Correct |
52 ms |
6148 KB |
Output is correct |
54 |
Correct |
401 ms |
11408 KB |
Output is correct |
55 |
Correct |
201 ms |
9452 KB |
Output is correct |
56 |
Correct |
48 ms |
6136 KB |
Output is correct |
57 |
Correct |
21 ms |
2012 KB |
Output is correct |
58 |
Correct |
133 ms |
8668 KB |
Output is correct |
59 |
Correct |
429 ms |
8700 KB |
Output is correct |
60 |
Correct |
21 ms |
2048 KB |
Output is correct |
61 |
Correct |
169 ms |
5152 KB |
Output is correct |
62 |
Correct |
475 ms |
9448 KB |
Output is correct |
63 |
Correct |
451 ms |
9452 KB |
Output is correct |
64 |
Correct |
479 ms |
9580 KB |
Output is correct |
65 |
Correct |
541 ms |
9452 KB |
Output is correct |
66 |
Correct |
493 ms |
9452 KB |
Output is correct |
67 |
Correct |
520 ms |
9624 KB |
Output is correct |
68 |
Correct |
508 ms |
9452 KB |
Output is correct |
69 |
Correct |
532 ms |
9452 KB |
Output is correct |
70 |
Correct |
517 ms |
9324 KB |
Output is correct |
71 |
Correct |
496 ms |
9448 KB |
Output is correct |
72 |
Correct |
390 ms |
9496 KB |
Output is correct |
73 |
Correct |
371 ms |
9584 KB |
Output is correct |