# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
747458 | vjudge1 | Kralj (COCI16_kralj) | C++17 | 2082 ms | 50428 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 ll long long
using namespace std;
const ll mod = 1000000007;
vector<int> v[500001];
vector<int> vec;
multiset<int> s;
int ans;
int ind, sz;
void solve() {
for(int i = ind; i < sz; i++) {
auto it = s.upper_bound(vec[i]);
if(it != s.end()) {
ans++;
s.erase(it);
}
else
s.erase(s.begin());
}
ind = sz;
}
signed main() {
int n;
cin >> n;
int a[n], b[n], c[n], be[n] = {}, en[n] = {};
for(int i = 0; i < n; i++) {
cin >> a[i];
be[a[i] - 1]++;
}
int x = 0;
for(int i = 0; i < n; i++) {
if(be[i]) {
en[(i + be[i] - 1) % n]++;
if(i + be[i] - 1 >= n)
x++;
}
}
int st = 0;
for(int i = 0; i < n; i++) {
x += (be[i] > 0);
if(be[i] && x == 1)
st = i;
x -= en[i];
}
for(int i = 0; i < n; i++)
cin >> b[i];
for(int i = 0; i < n; i++) {
cin >> c[i];
v[a[i] - 1].push_back(c[i]);
}
for(int i = 0; i <= n; i++) {
if(be[st] || i == n)
solve();
for(int j : v[st])
s.insert(j);
vec.push_back(b[st]);
st++;
sz++;
st %= n;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |