题解:P12643 [KOI 2024 Round 1] 回收退货

· · 题解

思路

卡车从 0 出发,需在 T_i 后经过 X_i ,最后返回到 0。最短时间为 \max(2 \cdot X_N, \max_i(T_i + X_i)) 。

最终时间复杂度 O(N)。

代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
int x[11451],t[11451];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>x[i];
    for(int i=1;i<=n;i++)cin>>t[i];
    int ans=2*x[n];
    for(int i=1;i<=n;i++)
        ans=max(ans,t[i]+x[i]);
    cout<<ans;
    return 0;
}