//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n;
llo aa[500001];
llo bb[500001];
llo ind[500001];
llo co[500001];
vector<llo> ss[500001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(llo i=0;i<n;i++){
cin>>ind[i];
ind[i]--;
co[ind[i]]++;
}
for(llo i=0;i<n;i++){
cin>>aa[i];
}
for(llo i=0;i<n;i++){
cin>>bb[i];
}
for(llo i=0;i<n;i++){
ss[ind[i]].pb(bb[i]);
}
for(llo i=1;i<n;i++){
co[i]+=co[i-1];
}
pair<llo,llo> mi={n+1,-1};
for(llo i=0;i<n;i++){
co[i]-=(i+1);
mi=min(mi,{co[i],i});
}
llo xx=(mi.b+1%n);
set<llo> cur;
llo ans=0;
for(llo i=0;i<n;i++){
for(auto j:ss[xx]){
cur.insert(j);
}
auto k=cur.upper_bound(aa[xx]);
if(k!=cur.end()){
ans++;
cur.erase(k);
}
else{
cur.erase(cur.begin());
}
xx=(xx+1)%n;
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2058 ms |
28256 KB |
Time limit exceeded |
2 |
Execution timed out |
2080 ms |
28128 KB |
Time limit exceeded |
3 |
Execution timed out |
2078 ms |
31584 KB |
Time limit exceeded |
4 |
Execution timed out |
2067 ms |
32096 KB |
Time limit exceeded |
5 |
Correct |
376 ms |
33004 KB |
Output is correct |
6 |
Correct |
331 ms |
33004 KB |
Output is correct |
7 |
Correct |
427 ms |
35304 KB |
Output is correct |
8 |
Correct |
360 ms |
33408 KB |
Output is correct |
9 |
Correct |
445 ms |
36716 KB |
Output is correct |
10 |
Correct |
358 ms |
35016 KB |
Output is correct |