Submission #139431

#TimeUsernameProblemLanguageResultExecution timeMemory
139431MinnakhmetovKralj (COCI16_kralj)C++14
70 / 140
798 ms51100 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define all(aaa) aaa.begin(), aaa.end() const int N = 5e5 + 5; vector<int> v[N]; int a[N], b[N]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { int x; cin >> x; v[a[i] - 1].push_back(x); } int need = 0; for (int i = 0; i < n; i++) { need += v[i].size(); need = max(0, need - 1); } set<int> st; for (int i = 0; i < need; i++) { for (int j : v[i]) st.insert(j); } int ans = 0; for (int i = need; i < n; i++) { for (int j : v[i]) st.insert(j); if (*st.rbegin() > b[i]) { st.erase(st.lower_bound(b[i])); ans++; } else { st.erase(st.begin()); } } for (int i = 0; i < need; i++) { for (int j : v[i]) st.insert(j); if (*st.rbegin() > b[i]) { st.erase(st.lower_bound(b[i])); ans++; } else { st.erase(st.begin()); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...