# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83635 | wjoao | Kralj (COCI16_kralj) | C++11 | 804 ms | 43436 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>
#define maxn 500010
using namespace std;
int n, dwarves[maxn], a, elves[maxn], sobras[maxn];
vector<int> f[maxn];
int main(){
scanf(" %d", &n);
for(int i = 1; i <= n; i++){
scanf(" %d", &a);
f[a].push_back(i);
}
for(int i = 1; i <= n; i++) scanf(" %d", &dwarves[i]);
for(int i = 1; i <= n; i++) scanf(" %d", &elves[i]);
for(int k = 0, j = 1, sobra = 0; k < 3*n; k++, j++, sobra--){
if( j == n+1 ) j = 1;
sobra = max(0, sobra);
sobras[j] = max(sobra, sobras[j]);
sobra += f[j].size();
}
int start_point;
for(int i = 1; i <= n; i++){
if(sobras[i] == 0){
start_point = i;
break;
}
}
int vitorias = 0;
int j = start_point;
set<int> pokemon;
while(true){
for(int k = 0; k < f[j].size(); k++){
pokemon.insert(elves[f[j][k]]);
}
set<int>::iterator it = pokemon.upper_bound(dwarves[j]);
if(it == pokemon.end()){
it = pokemon.begin();
}
if( *it > dwarves[j]) {
vitorias++;
}
pokemon.erase(it);
j++;
if( j == n+1 ) j = 1;
if( j == start_point ) break;
}
printf("%d\n", vitorias);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |