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 sts(v) stable_sort(v.BE, v.E)
#define Rsts(v) stable_sort(v.rBE, v.rE)
#define rev(v) reverse(v.BE, v.E)
#define BE begin()
#define rBE rbegin()
#define E end()
#define rE rend()
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
using namespace std;
using ll = long long;
using T = pair<ll, ll>;
const int M = 998244353;
struct ABI{
vector<pair<int, int>> abi;
ABI(int n){
abi.resize(n + 1);
}
void updt(int ini, int val){
for(int i = ini; i < (int)abi.size(); i += i & -i){
if(abi[i].F < val)
abi[i] = {val, ini};
else if(abi[i].F == val)
abi[i].S = min(ini, abi[i].S);
}
}
pair<int, int> query(int i){
pair<int, int> ans = {0, 0};
for(; i > 0; i -= i & -i)
if(ans.F < abi[i].F)
ans = abi[i];
return ans;
}
};
int bs(vector<int> &v, int val) {
int l = 1, r = v.size() - 1, ans = -1;
while(l < r) {
int m = (l + r) / 2;
if(v[m] <= val) l = m + 1, ans = m;
else r = m - 1;
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// st para guardar la respuesta en la caja i
// dp[i] = query(1, n - 1)
int n, m; cin >> n >> m;
vector<pair<int, int>> v(n + 1, {INT_MIN, INT_MIN});
vector<int> F(m + 1, INT_MIN);
for(int i = 1; i <= n; i++){
int w, val; cin >> w >> val;
v[i] = {val, w};
}
for(int i = 1; i <= m; i++)
cin >> F[i];
sts(F);
sts(v);
int res = 0;
ABI abi(m);
vector<pair<int, int>> dp(n + 1, {0, 0});
dp[0] = {0, 0};
for(int i = 1; i <= n; i++){
dp[i].S = lower_bound(F.BE, F.E, v[i].S) - F.BE;
if(dp[i].S == m + 1)continue;
for(int j = 1; j < i; j++){
if(dp[j].S != m){
if(dp[j].F + 1 > dp[i].F)dp[i] = {dp[j].F + 1, max(dp[i].S, dp[j].S + 1)};
else if(dp[j].F == dp[i].F)dp[i].S = min(dp[i].S, dp[j].S);
}
}
if(!dp[i].F)dp[i].F = 1;
res = max(res, dp[i].F);
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |