#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1083 ms |
47320 KB |
Output is correct |
2 |
Correct |
621 ms |
46184 KB |
Output is correct |
3 |
Correct |
884 ms |
54636 KB |
Output is correct |
4 |
Correct |
836 ms |
55112 KB |
Output is correct |
5 |
Correct |
429 ms |
34284 KB |
Output is correct |
6 |
Correct |
412 ms |
34200 KB |
Output is correct |
7 |
Correct |
494 ms |
38200 KB |
Output is correct |
8 |
Correct |
484 ms |
36244 KB |
Output is correct |
9 |
Correct |
531 ms |
39400 KB |
Output is correct |
10 |
Correct |
516 ms |
35960 KB |
Output is correct |