CF1555C题解
-
分析
看着感觉很不可做,因为第一个人走的方式有巨大的后效性。
但是发现 ,那么第一个人走的方式一定是先在上面走一段,再在下面走一段(直接走下面视为先在上面走了 个数)
设第一个人在 处从第一行下去,那么第二个人能选择的数之和一定为第一行 的后缀和或者第二行 的前缀和的最大值。
第一个人可以决定 ,他肯定会取后缀和前缀和最大值最小的位置 。
线性扫一遍即可。 -
代码
#include <iostream>
using namespace std;
constexpr int MAXN(1000007);
constexpr int INF(0x3f3f3f3f);
int a[MAXN], b[MAXN], sa[MAXN], pb[MAXN];
int T, n;
inline void read(int &temp) { cin >> temp; }
inline void work() {
int ans(INF);
read(n);
for (int i(1); i <= n; ++i) read(a[i]);
for (int i(1); i <= n; ++i) read(b[i]);
sa[n + 1] = 0;
for (int i(n); i; --i) sa[i] = sa[i + 1] + a[i];
for (int i(1); i <= n; ++i) pb[i] = pb[i - 1] + b[i];
for (int i(1); i <= n; ++i) ans = min(ans, max(sa[i + 1], pb[i - 1]));
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
read(T);
while (T--) work();
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】