/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Wrong Answer 2ms 484.0 KiB
#3 Wrong Answer 9ms 320.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 = 1e12;
    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];
            if (cur >= 0)
                mina = min(mina, cur);
        }
    }

    ll minb = 1e12;
    ll first = 0;
    last=pos[n-1];
    for (ll i = n - 1; i > -1; i--)
    {
        if (len[i] > min(a,b))
        {
            det = 0;
            first += (last - pos[i]);
            cur = pos[i] - first;
            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-02 19:26:45
Judged At
2024-11-11 03:43:01
Judged By
Score
10
Total Time
9ms
Peak Memory
484.0 KiB