/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 412.0 KiB
#2 Accepted 1ms 416.0 KiB
#3 Accepted 6ms 456.0 KiB
#4 Accepted 18ms 2.004 MiB
#5 Accepted 16ms 1.184 MiB
#6 Accepted 21ms 1.191 MiB
#7 Accepted 12ms 1.152 MiB
#8 Accepted 27ms 1.152 MiB
#9 Accepted 16ms 1.254 MiB
#10 Accepted 11ms 572.0 KiB

Code

#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;

            cur = last - pos[i]-pos[i];
            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 - first*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 06:02:52
Judged At
2024-03-04 15:04:53
Judged By
Score
100
Total Time
27ms
Peak Memory
2.004 MiB