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 pb push_back
#define mp make_pair
#define mt make_tuple
#define int long long
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
int N, Q, X[200005];
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> X[i];
}
cin >> Q;
for (int S; Q--; ) {
cin >> S;
set<int> T;
for (int i = 1; i <= N; i++) {
T.insert(X[i]);
}
int cur = 0, chng = 0;
bool dir = 0;
for (int i = 1; i <= N; i++) {
auto it = T.lower_bound(S);
int x = (int)-1e16, y = (int)1e16;
if (it != T.end()) {
y = *it;
}
if (it != T.begin()) {
--it;
x = *it;
++it;
}
cur += min(S - x, y - S);
if (S - x <= y - S) {
if (dir == 1) chng++;
dir = 0;
T.erase(x);
S = x;
} else {
if (dir == 0) chng++;
dir = 1;
T.erase(y);
S = y;
}
}
cout << cur << '\n';
assert(chng <= 60);
}
}
Compilation message (stderr)
travel.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
14 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |