# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
747396 | 2023-05-24T06:52:42 Z | vjudge1 | Kralj (COCI16_kralj) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include <array> #define all(v) (v.begin()), (v.end()) #define setall(a, val) for(auto& x : a) x = val #define ll long long #define cerr (cerr << "D: ") clock_t start_time; using namespace std; double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; } void init(bool oj = 1) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); start_time = clock(); if (oj) { #ifndef ONLINE_JUDGE FILE* _ = freopen("in.txt", "r", stdin); //FILE* __ = freopen("out.txt", "w", stdout); #endif } } const ll MOD = 1e9 + 7; const ll N = 5e5 + 7; const ll M = 2e3 + 7; //#################################################################################### int n; bool vis[N]; vector<int> a; multiset<int> b; int solve(int i) { if (i == n) return 0; int mx = 0, f = *b.begin(); b.erase(b.begin()); mx = max(mx, solve(i + 1) + (f > a[i])); b.insert(f); auto it = b.lower_bound(a[i]); if (it == b.end()) return mx; f = *it; b.erase(it); mx = max(mx, solve(i + 1) + (f > a[i])); b.insert(f); auto it = b.upper_bound(a[i]); if (it == b.end()) return mx; f = *it; b.erase(it); mx = max(mx, solve(i + 1) + (f > a[i])); b.insert(f); return mx; } int main() { init(0); cin >> n; a.resize(n); for (int i = 0; i < n; i++) {int _; cin >> _;} for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { int x; cin >> x; b.insert(x); } cout << solve(0) << endl; cerr << get_time() << "s" << endl; }