/**
* user: karagyozov-c76
* fname: Ivo
* lname: Karagyozov
* task: santa
* score: 30.0
* date: 2019-10-11 07:14:23.928835
*/
#include <bits/stdc++.h>
const int32_t MAX_N = 96068;
int32_t n, x[MAX_N + 5], h[MAX_N + 5], v[MAX_N + 5];
bool check(int32_t left, int32_t right) {
for(int32_t i = right + 1; i < n; i++) {
if(h[i] == 0) {
return false;
}
}
std::multiset< int32_t > s;
for(int32_t i = 0; i <= right; i++) {
if(h[i] == 0) {
s.insert(v[i]);
}
else {
if(i < left) {
auto it = s.lower_bound(v[i]);
if(it != s.end()) {
s.erase(it);
}
}
}
}
for(int32_t i = right; i >= left; i--) {
if(h[i] == 1) {
auto it = s.lower_bound(v[i]);
if(it != s.end()) {
s.erase(it);
}
}
}
return s.empty();
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t t;
std::cin >> t;
for(int32_t cs = 1; cs <= t; cs++) {
std::cin >> n;
for(int32_t i = 0; i < n; i++) {
std::cin >> x[i];
}
for(int32_t i = 0; i < n; i++) {
std::cin >> h[i];
}
for(int32_t i = 0; i < n; i++) {
std::cin >> v[i];
}
int32_t last = -1;
for(int32_t i = 0; i < n; i++) {
while(last < i && check(last + 1, i)) {
last++;
}
if(last == -1) {
std::cout << -1 << " ";
}
else {
std::cout << 2 * x[i] - x[last] << " ";
}
}
std::cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
613 ms |
552 KB |
Output is correct |
4 |
Execution timed out |
1075 ms |
616 KB |
Time limit exceeded |
5 |
Execution timed out |
1018 ms |
504 KB |
Time limit exceeded |
6 |
Execution timed out |
1016 ms |
632 KB |
Time limit exceeded |
7 |
Execution timed out |
1000 ms |
1144 KB |
Time limit exceeded |
8 |
Execution timed out |
1079 ms |
1400 KB |
Time limit exceeded |
9 |
Execution timed out |
1061 ms |
2808 KB |
Time limit exceeded |
10 |
Execution timed out |
1062 ms |
2808 KB |
Time limit exceeded |