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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
ll dp[2][1001],cc;
vi c;
vii paint;
ii s;
bool taken[1001];
int main(){
	int n,m;cin>>n>>m;
	for(int i = 0; i < n; i++){
		cin >> s.se >> s.fi;
		paint.pb(s);
	}
	sort(paint.begin(),paint.end());
	for(int i = 0; i < m; i++){
		cin >> cc;
		c.pb(cc);
	}
	c.pb(0);
	sort(c.begin(),c.end());
	ll ans=0;
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= m; j++){
			dp[i%2][j]=dp[(i+1)%2][j];
			if(paint[i].se<=c[j] && taken[j]==0){
				taken[j]=1;
				for(int k = j+1; k <= m; k++){
					dp[i%2][k]=dp[(i+1)%2][k]+1;
					ans=max(ans,dp[i%2][k]);
				}
				j=m+1;
			}
		}
	}
	cout<<ans<<'\n';
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |