# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259618 | dantoh000 | Santa Claus (RMI19_santa) | C++14 | 1095 ms | 760 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;
int n;
int x[6000], h[6000], v[6000];
bool test(int l, int r){
multiset<int> ms;
for (int i = 0; i < l; i++){
if (h[i]){
auto it = ms.lower_bound(v[i]);
if (it != ms.end()) ms.erase(it);
}
else{
ms.insert(v[i]);
}
}
for (int i = l; i <= r; i++){
if (h[i] == 0) ms.insert(v[i]);
}
for (int i = l; i <= r; i++){
if (h[i] == 1){
auto it = ms.lower_bound(v[i]);
if (it != ms.end()) ms.erase(it);
}
}
return ms.empty();
}
int main(){
int tc;
scanf("%d",&tc);
while (tc--){
scanf("%d",&n);
int lastelf = 0;
for (int i = 0; i < n; i++){
scanf("%d",&x[i]);
}
for (int i = 0; i < n; i++){
scanf("%d",&h[i]);
if (h[i] == 0) lastelf = i;
}
for (int i = 0; i < n; i++){
scanf("%d",&v[i]);
}
for (int i = 0; i < n; i++){
if (i < lastelf){
printf("-1 ");
continue;
}
int lo = 0, hi = i;
while (lo < hi){
int mid = (lo+hi+1)/2;
if (test(mid,i)){
lo = mid;
}
else hi = mid-1;
}
if (test(lo,i)){
printf("%d ",2*x[i]-x[lo]);
}
else printf("-1 ");
}
printf("\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |