Submission #1335033

#TimeUsernameProblemLanguageResultExecution timeMemory
1335033SulAExhibition (JOI19_ho_t2)C++20
50 / 100
1095 ms23772 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n,m; cin >> n >> m;
    pair<int,int> paint[n];
    int frame[m];
    for (auto& [v, s] : paint) cin >> s >> v;
    for (int& f : frame) cin >> f;
    map<int, vector<int*>> comp;
    for (int i = 0; i < n; i++) {
        auto& [v, s] = paint[i];
        comp[v].push_back(&v);
        comp[s].push_back(&s);
    }
    for (int i = 0; i < m; i++) {
        comp[frame[i]].push_back(&frame[i]);
    }
    int z = 0;
    for (auto [_, list] : comp) {
        for (auto i : list) {
            *i = z;
        }
        z++;
    }

    sort(paint, paint + n, greater<>());
    sort(frame, frame + m, greater<>());
    int dp[n], ans = 0;
    for (int i = 0; i < n; i++) {
        dp[i] = 0;
        auto [vi, si] = paint[i];
        for (int j = 0; j < i; j++) {
            auto [vj, sj] = paint[j];
            if (vj >= vi) {
                dp[i] = max(dp[i], dp[j] + 1);
            }
        }
        dp[i] = min(dp[i], m-1);
        while (dp[i] >= 0 && si > frame[dp[i]])
            dp[i]--;
        ans = max(ans, 1 + dp[i]);
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...