답안 #386268

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386268 2021-04-06T08:49:19 Z kshitij_sodani Kralj (COCI16_kralj) C++14
84 / 140
2000 ms 26524 KB
//#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'


int n;
int aa[500001];
int bb[500001];
int ind[500001];

int co[500001];
vector<int> ss[500001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>ind[i];
		ind[i]--;
		co[ind[i]]++;
	}

	for(int i=0;i<n;i++){
		cin>>aa[i];

	}
	for(int i=0;i<n;i++){
		cin>>bb[i];
	}
	for(int i=0;i<n;i++){
		ss[ind[i]].pb(bb[i]);
	}
	for(int i=1;i<n;i++){
		co[i]+=co[i-1];
	}
	pair<int,int> mi={n+1,-1};
	for(int i=0;i<n;i++){
		co[i]-=(i+1);
		if(co[i]<mi.a){
			mi={co[i],i};
		}
	}
	int xx=(mi.b+1%n);
	set<int> cur;
	int ans=0;
	for(int 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);
		if(xx==n){
			xx=0;
		}
	}




	cout<<ans<<endl;









 
 
	return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2084 ms 20068 KB Time limit exceeded
2 Execution timed out 2058 ms 19940 KB Time limit exceeded
3 Execution timed out 2083 ms 21732 KB Time limit exceeded
4 Execution timed out 2066 ms 22044 KB Time limit exceeded
5 Correct 342 ms 22508 KB Output is correct
6 Correct 286 ms 23056 KB Output is correct
7 Correct 410 ms 25836 KB Output is correct
8 Correct 326 ms 25196 KB Output is correct
9 Correct 422 ms 26524 KB Output is correct
10 Correct 361 ms 24044 KB Output is correct