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>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,m;
cin>>n>>m;
pair<ll,ll>pr[n+5];
for(ll i=1;i<=n;i++){
cin>>pr[i].ss>>pr[i].ff;
}
ll c[m+5];
for(ll i=1;i<=m;i++){
cin>>c[i];
}
sort(pr+1,pr+n+1);
sort(c+1,c+m+1);
ll dp[n+5][m+5];
memset(dp,0,sizeof dp);
for(ll i=1;i<=n;i++){
for(ll j=1;j<=m;j++){
if(pr[i].ss>c[j]){
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
else{
dp[i][j]=max({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]+1});
}
}
}
cout<<dp[n][m];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |