# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139435 | Minnakhmetov | Kralj (COCI16_kralj) | C++14 | 770 ms | 42344 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>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 5e5 + 5;
vector<int> v[N];
int a[N], b[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v[a[i] - 1].push_back(x);
}
int stock = 0;
for (int i = 0; i < n; i++) {
stock += v[i].size();
stock = max(0, stock - 1);
}
int start;
for (int i = 0; i < n; i++) {
stock += v[i].size();
stock = max(0, stock - 1);
if (stock == 0) {
start = (i + 1) % n;
break;
}
}
set<int> st;
int ans = 0;
for (int i = start; i < n; i++) {
for (int j : v[i])
st.insert(j);
if (*st.rbegin() > b[i]) {
st.erase(st.upper_bound(b[i]));
ans++;
}
else {
st.erase(st.begin());
}
}
for (int i = 0; i < start; i++) {
for (int j : v[i])
st.insert(j);
if (*st.rbegin() > b[i]) {
st.erase(st.upper_bound(b[i]));
ans++;
}
else {
st.erase(st.begin());
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |