# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
260775 | thecodingwizard | Kralj (COCI16_kralj) | C++11 | 762 ms | 51048 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0); ios_base::sync_with_stdio(false);
int n; cin >> n;
vector<int> adversaries[n];
for (int i = 0; i < n; i++) {
int x; cin >> x;
adversaries[x-1].push_back(i);
}
int D[n], E[n];
for (int i = 0; i < n; i++) cin >> D[i];
for (int i = 0; i < n; i++) cin >> E[i];
int ctr = 0;
for (int i = 0; i < n; i++) {
ctr = max(0, ctr - 1 + (int)adversaries[i].size());
}
int startIdx = -1;
for (int i = 0; i < n; i++) {
if (ctr == 0) {
startIdx = i;
break;
}
ctr = ctr - 1 + (int)adversaries[i].size();
assert(ctr >= 0);
}
multiset<int> elves;
int ans = 0;
for (int i = 0; i < n; i++) {
int idx = (startIdx + i) % n;
for (int elf : adversaries[idx]) {
elves.insert(E[elf]);
}
auto it = elves.upper_bound(D[idx]);
if (it == elves.end()) {
elves.erase(elves.begin());
} else {
elves.erase(it);
ans++;
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |