# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98347 | dalgerok | Kralj (COCI16_kralj) | C++17 | 1083 ms | 55112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |