# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259636 | lyc | Santa Claus (RMI19_santa) | C++14 | 1099 ms | 1656 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 TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int mxN = 96068 + 5;
int T, N, X[mxN], H[mxN], V[mxN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> T;
while (T--) {
cin >> N;
FOR(i,1,N){ cin >> X[i]; }
FOR(i,1,N){ cin >> H[i]; }
FOR(i,1,N){ cin >> V[i]; }
int totElf = 0;
FOR(i,1,N) if (H[i] == 0) ++totElf;
FOR(i,1,N){
int ans = -1;
X[0] = -1;
FOR(k,0,N){
if (X[k] > X[i]) break;
int cnt = 0;
multiset<int> gifts;
multiset<int> received;
int rt = -1;
FOR(j,1,N){
if (X[j] > X[i]) break;
rt = j;
if (H[j] == 0) {
gifts.insert(V[j]);
++cnt;
} else if (X[j] <= X[k]) {
auto it = gifts.lower_bound(V[j]);
if (it != gifts.end()) {
gifts.erase(it);
received.insert(j);
}
}
}
if (cnt != totElf) break;
//~ if (k < 5) continue;
int lt = -1;
RFOR(j,rt,1){
if (H[j] == 1 && received.count(j) == 0) {
auto it = gifts.lower_bound(V[j]);
//~ if (it != gifts.end()) TRACE(j _ V[j] _ *it);
if (it != gifts.end()) gifts.erase(it);
if (gifts.empty()) { lt = j; break; }
}
}
if (lt != -1) {
int cur = 2*X[rt]-X[lt];
//~ TRACE(k _ cur);
if (ans == -1 || ans > cur) ans = cur;
} //else TRACE("");
}
cout << ans << ' ';
}
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |