/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 740.0 KiB
#3 Accepted 9ms 580.0 KiB
#4 Accepted 18ms 2.066 MiB
#5 Accepted 18ms 1.297 MiB
#6 Accepted 18ms 1.316 MiB
#7 Accepted 18ms 1.297 MiB
#8 Accepted 17ms 1.301 MiB
#9 Accepted 18ms 1.316 MiB
#10 Accepted 17ms 724.0 KiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(a) a.begin(), a.end()
#define endl '\n'

void solve()
{
    ll a, b;
    cin >> a >> b;
    ll n;
    cin >> n;
    vector<ll> pos(n), len(n);
    for (auto &x : pos)
        cin >> x;
    for (auto &x : len)
        cin >> x;
    ll last = pos[n - 1];

    ll mina = 1e18;
    ll cur;
    ll det = 1;

    for (ll i = 0; i < n; i++)
    {
        if (len[i] > min(a,b))
        {
            det = 0;

            //last -= pos[i];

            cur = last - pos[i]*2;
            if (cur >= 0)
                mina = min(mina, cur);
        }
    }

    ll minb = 1e18;
    ll first = 0;
    last=pos[n-1];
    cur=0;
    for (ll i = n - 1; i > -1; i--)
    {
        if (len[i] > min(a,b))
        {
            det = 0;
            //first += (last - pos[i]);
            cur = last - (last-pos[i])*2;
            if(cur>=0)minb = min(minb, cur);
        }
    }
    if (det)
        cout << -1 << endl;
    else
        cout << min(mina, minb) << endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1030 A boring train journey
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-04 05:44:46
Judged At
2024-10-03 14:02:19
Judged By
Score
100
Total Time
18ms
Peak Memory
2.066 MiB