This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e3+5;
int dp[N][N],prm[N][N];
signed main(){
int n,m;
cin>>n>>m;
vector <pair <int,int> > v(n);
vector <int> c(m);
for(int i=0;i<n;i++){
cin>>v[i].ff>>v[i].ss;
swap(v[i].ff,v[i].ss);
}
for(int i=0;i<m;i++){
cin>>c[i];
}
sort(all(v));
sort(all(c));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(v[i].ss<=c[j])dp[i][j]=1;
if(i-1>=0 && j-1>=0)dp[i][j]+=dp[i-1][j-1];
if(j-1>=0)prm[i][j]=max(dp[i][j],prm[i][j-1]);
else prm[i][j]=dp[i][j];
}
}
cout<<dp[n-1][m-1]<<"\n";
}
/*
3 4 10 20 51 35
4
6
10
4
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
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |