# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
796148 | 2023-07-28T07:04:07 Z | 박상훈(#10069) | Bitaro's travel (JOI23_travel) | C++17 | 3000 ms | 11856 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr ll INF = 4e18; ll X[200200]; int main(){ int n; scanf("%d", &n); for (int i=1;i<=n;i++) scanf("%lld", X+i); int q; scanf("%d", &q); while(q--){ int x; scanf("%d", &x); multiset<int> st; for (int i=1;i<=n;i++) st.insert(X[i]); ll ans = 0; while(!st.empty()){ auto iter = st.lower_bound(x); ll L = (iter==st.begin())?-INF:*prev(iter); ll R = (iter==st.end())?INF:*iter; if (abs(x-L) <= abs(x-R)){ ans += abs(x-L); x = L; assert(iter!=st.begin()); st.erase(prev(iter)); } else{ ans += abs(x-R); x = R; assert(iter!=st.end()); st.erase(iter); } } printf("%lld\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 308 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 308 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 60 ms | 11636 KB | Output is correct |
18 | Correct | 63 ms | 11640 KB | Output is correct |
19 | Correct | 60 ms | 11704 KB | Output is correct |
20 | Correct | 60 ms | 11752 KB | Output is correct |
21 | Correct | 58 ms | 11752 KB | Output is correct |
22 | Correct | 68 ms | 11856 KB | Output is correct |
23 | Correct | 59 ms | 11640 KB | Output is correct |
24 | Correct | 57 ms | 11680 KB | Output is correct |
25 | Correct | 63 ms | 11752 KB | Output is correct |
26 | Correct | 62 ms | 11696 KB | Output is correct |
27 | Correct | 61 ms | 11680 KB | Output is correct |
28 | Correct | 68 ms | 11692 KB | Output is correct |
29 | Correct | 59 ms | 11652 KB | Output is correct |
30 | Correct | 59 ms | 11708 KB | Output is correct |
31 | Correct | 68 ms | 11648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 312 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Execution timed out | 3039 ms | 11696 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 308 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 60 ms | 11636 KB | Output is correct |
18 | Correct | 63 ms | 11640 KB | Output is correct |
19 | Correct | 60 ms | 11704 KB | Output is correct |
20 | Correct | 60 ms | 11752 KB | Output is correct |
21 | Correct | 58 ms | 11752 KB | Output is correct |
22 | Correct | 68 ms | 11856 KB | Output is correct |
23 | Correct | 59 ms | 11640 KB | Output is correct |
24 | Correct | 57 ms | 11680 KB | Output is correct |
25 | Correct | 63 ms | 11752 KB | Output is correct |
26 | Correct | 62 ms | 11696 KB | Output is correct |
27 | Correct | 61 ms | 11680 KB | Output is correct |
28 | Correct | 68 ms | 11692 KB | Output is correct |
29 | Correct | 59 ms | 11652 KB | Output is correct |
30 | Correct | 59 ms | 11708 KB | Output is correct |
31 | Correct | 68 ms | 11648 KB | Output is correct |
32 | Correct | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 312 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 0 ms | 212 KB | Output is correct |
38 | Execution timed out | 3039 ms | 11696 KB | Time limit exceeded |
39 | Halted | 0 ms | 0 KB | - |