Submission #98347

#TimeUsernameProblemLanguageResultExecution timeMemory
98347dalgerokKralj (COCI16_kralj)C++17
140 / 140
1083 ms55112 KiB
#include<bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n, a[N], p[N], v[N], pref[N]; vector < int > g[N]; multiset < int > q; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n; i++){ cin >> p[i]; } for(int i = 1; i <= n; i++){ cin >> v[i]; pref[a[i]] += 1; g[a[i]].push_back(v[i]); } pair < int, int > mn = make_pair(N, N); for(int i = 1; i <= n; i++){ pref[i] += pref[i - 1]; mn = min(mn, make_pair(pref[i] - i, i)); } int pos = mn.second; if(pos == n){ pos = 1; } else{ pos += 1; } int ans = 0; for(int i = pos, j = 1; j <= n; i = (i == n ? 1 : i + 1), j++){ for(auto it : g[i]){ q.insert(it); } auto it = q.upper_bound(p[i]); if(it == q.end()){ q.erase(q.begin()); } else{ q.erase(it); ans += 1; } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...