跳到正文

题解

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

Heart_of_Iron约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年5月29日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 1 分钟
获赞
5
题目
P12643

版本

  1. v1当前

思路

卡车从 00 出发,需在 TiT_i 后经过 XiX_i ,最后返回到 00。最短时间为 max⁡(2⋅XN,max⁡i(Ti+Xi))\max(2 \cdot X_N, \max_i(T_i + X_i)) 。

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

代码

C++
#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;
}
原文
存档评论7 条抓取于