# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163050 | _qVp_ | Kralj (COCI16_kralj) | C++14 | 919 ms | 53164 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;
typedef pair < int, int > II;
const int md = 5e5 + 10;
int n;
int a[md], b[md], pre[md];
vector < int > adj[md];
int solve(int start) {
int res = 0;
set < int > S;
for(int i = start, j = 1; j <= n; j++, i = i % n + 1) {
for(int j = 0; j < adj[i].size(); j++)
S.insert(adj[i][j]);
set < int > :: iterator it = S.upper_bound(b[i]);
if (it == S.end())
S.erase(S.begin());
else {
S.erase(it);
res++;
}
}
return res;
}
int main() {
//freopen("test.in", "r", stdin);
ios_base::sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = -1;
}
for(int i = 1; i <= n; i++)
cin >> b[i];
II start = II(1e9, 1e9);
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
adj[a[i]].push_back(x);
//cout << a[i] << " " << x << endl;
pre[a[i]]++;
}
for(int i = 1; i <= n; i++) {
pre[i] += pre[i - 1];
start = min(start, II(pre[i], i));
}
cout << solve(start.second % n + 1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |