#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
void solve(){
int n,m;
cin>>n>>m;
vector<int>frames(m);
vector<pair<int,int>>pictures_pairs(n);
vector<int>pictures(n);
for(auto&i:pictures_pairs)
cin>>i.second>>i.first;
for(int&i:frames)
cin>>i;
sort(pictures_pairs.begin(),pictures_pairs.end());
sort(frames.begin(),frames.end());
for(int i=0;i<n;i++)
pictures[i]=pictures_pairs[i].second;
vector<int>dp(n+1); // if you use picture i and all after, whats the max you can put inside?
for(int i=n-1;i>=0;i--){
int l=-1,r=m+1;
while(l<r-1){
int mid=(l+r)/2;
if(frames[mid]>=pictures[i])
r=mid;
else
l=mid;
}
// r is good, l is bad, if l = -1, then none is bad, if r = n, then none is good
if(r==m)
continue;
dp[i]=min(dp[i+1],m-r-1)+1;
dp[i]=max(dp[i],dp[i+1]);
}
cout<<dp[0]<<"\n";
}
int main(){
ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
//freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
int t=1;//cin>>t;
while(t--)solve();
return 0;
}
/*
3 4
10 20
5 1
3 5
4
6
10
4
2
3 2
1 2
1 2
1 2
1
1
2
4 2
28 1
8 8
6 10
16 9
4
3
0
8 8
508917604 35617051
501958939 840246141
485338402 32896484
957730250 357542366
904165504 137209882
684085683 775621730
552953629 20004459
125090903 607302990
433255278
979756183
28423637
856448848
276518245
314201319
666094038
149542543
3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
488 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
452 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
488 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
42 ms |
5184 KB |
Output is correct |
39 |
Correct |
37 ms |
5072 KB |
Output is correct |
40 |
Correct |
34 ms |
5196 KB |
Output is correct |
41 |
Correct |
43 ms |
5212 KB |
Output is correct |
42 |
Correct |
38 ms |
5212 KB |
Output is correct |
43 |
Correct |
38 ms |
5200 KB |
Output is correct |
44 |
Correct |
42 ms |
5320 KB |
Output is correct |
45 |
Correct |
46 ms |
5200 KB |
Output is correct |
46 |
Correct |
37 ms |
5200 KB |
Output is correct |
47 |
Correct |
50 ms |
4688 KB |
Output is correct |
48 |
Correct |
35 ms |
4692 KB |
Output is correct |
49 |
Correct |
39 ms |
4696 KB |
Output is correct |
50 |
Correct |
32 ms |
4424 KB |
Output is correct |
51 |
Correct |
39 ms |
5088 KB |
Output is correct |
52 |
Correct |
38 ms |
5196 KB |
Output is correct |
53 |
Correct |
38 ms |
5124 KB |
Output is correct |
54 |
Correct |
34 ms |
5084 KB |
Output is correct |
55 |
Correct |
48 ms |
5204 KB |
Output is correct |
56 |
Correct |
31 ms |
4052 KB |
Output is correct |
57 |
Correct |
14 ms |
1628 KB |
Output is correct |
58 |
Correct |
23 ms |
3820 KB |
Output is correct |
59 |
Correct |
30 ms |
3920 KB |
Output is correct |
60 |
Correct |
14 ms |
1628 KB |
Output is correct |
61 |
Correct |
26 ms |
2900 KB |
Output is correct |
62 |
Correct |
47 ms |
5216 KB |
Output is correct |
63 |
Correct |
46 ms |
5204 KB |
Output is correct |
64 |
Correct |
48 ms |
5200 KB |
Output is correct |
65 |
Correct |
48 ms |
5212 KB |
Output is correct |
66 |
Correct |
54 ms |
5196 KB |
Output is correct |
67 |
Correct |
47 ms |
5200 KB |
Output is correct |
68 |
Correct |
47 ms |
5200 KB |
Output is correct |
69 |
Correct |
49 ms |
5204 KB |
Output is correct |
70 |
Correct |
49 ms |
5212 KB |
Output is correct |
71 |
Correct |
53 ms |
5200 KB |
Output is correct |
72 |
Correct |
49 ms |
5204 KB |
Output is correct |
73 |
Correct |
43 ms |
5204 KB |
Output is correct |