# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
661472 |
2022-11-25T21:28:41 Z |
as111 |
Kralj (COCI16_kralj) |
C++14 |
|
810 ms |
54908 KB |
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#define MAXN 500000
using namespace std;
int N;
int dwarves[MAXN+5];
int elves[MAXN+5];
int A[MAXN+5];
int net[MAXN+5]; // net amount of elves
vector <int> matches[MAXN+5];
int ans;
set <int> curr;
void solve(int start) {
ans = 0;
for (int i = start, j = 0; j < N; j++, i = (i + 1) % N) {
for (auto e : matches[i]) curr.insert(e); // all that start here
auto it = curr.upper_bound(dwarves[i]); // number right above used
if (it == curr.end()) {
curr.erase(curr.begin());
}
else {// bottom can't be used
ans++;
curr.erase(it); // use the number right above
}
}
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i]; A[i]--;// 0 based
}
for (int i = 0; i < N; i++) {
cin >> dwarves[i];
}
fill(net, net + MAXN, -1); // each empty space starts at -1, even out to 0
for (int i = 0; i < N; i++) {
cin >> elves[i];
net[A[i]]++;
matches[A[i]].push_back(elves[i]);
}
int pos = -1;
int mn = MAXN+1;//min
for (int i = 0; i < N; i++) {
if (i!=0) net[i] += net[i - 1];
if (net[i] < mn) {
mn = net[i];
pos = i;
}
}
int start = (pos + 1) % N; // start right after most negative spot
solve(start);
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
810 ms |
47572 KB |
Output is correct |
2 |
Correct |
553 ms |
46424 KB |
Output is correct |
3 |
Correct |
723 ms |
54448 KB |
Output is correct |
4 |
Correct |
728 ms |
54908 KB |
Output is correct |
5 |
Correct |
597 ms |
34360 KB |
Output is correct |
6 |
Correct |
536 ms |
34128 KB |
Output is correct |
7 |
Correct |
654 ms |
37976 KB |
Output is correct |
8 |
Correct |
590 ms |
36396 KB |
Output is correct |
9 |
Correct |
699 ms |
39348 KB |
Output is correct |
10 |
Correct |
608 ms |
35680 KB |
Output is correct |