Submission #1084068

#TimeUsernameProblemLanguageResultExecution timeMemory
1084068May27_thExhibition (JOI19_ho_t2)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define i64 long long #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() void Maximize(pair<int, int> &a, pair<int, int> b) { if (a.first < b.first) a = b; else if (a.first == b.first) a.second = min(a.second, b.second); } void Solve(void) { int N, M; cin >> N >> M; vector<pair<int, int>> pics(N), f(N + 2, mp(-1, -1)); for (int i = 0; i < N; i ++) { cin >> pics[i].second >> pics[i].first; } vector<int> frames; for (int i = 0; i < M; i ++) { int x; cin >> x; frames.pb(x); } sort(all(frames)); sort(all(pics)); stack<int> s; int ans = 0; for (int i = 0; i < N; i ++) { // cout << pics[i].first << " " << pics[i].second << "\n"; while (!s.empty() && pics[s.top()].second > pics[i].second) { if (f[s.top()].second < M - 1 && f[s.top()].first != -1) { Maximize(f[i], mp(f[s.top()].first + 1, f[s.top()].second + 1)); } s.pop(); } int p = lower_bound(all(frames), pics[i].second) - frames.begin(); if (p != M) { Maximize(f[i], mp(1, p)); if (!s.empty()) { int curp = max(f[s.top()].second + 1, p); if (curp < M && f[s.top()].first != -1) { Maximize(f[i], mp(f[s.top()].first + 1, curp)); } } } s.push(i); ans = max(ans, f[i].first); // cout << pics[i].second << " " << f[i].first << " " << f[i].second << "\n"; } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int Tests = 1; // cin >> Tests; while (Tests --) { Solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...