Submission #792426

# Submission time Handle Problem Language Result Execution time Memory
792426 2023-07-25T04:43:23 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

ll INF = 1e9 + 10;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int x[n + 2] = {};
    for(int i = 1; i <= n; i++) 
        cin >> x[i];
    int q;
    cin >> q;
    while(q--) {
        ll ans = 0;
        ll cur;
        cin >> cur;
        int cnt = 1;
        int l = 0, r = 0;
        while(l <= n && x[l + 1] < cur) l++;
        while(r <= n && x[r] <= cur) r++;
        while(cnt < n) {
            int w1 = (l > 0 ? cur - x[l] : INF);
            int w2 = (r < n + 1 ? x[r] - cur : INF);
            ans += min(w1, w2);
            if(w1 <= w2) cur = x[l--];
            else cur = x[r++];
            cnt++;
        }
        cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -