B. Red and Blue1000 / 思维

Posted 幽殇默

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B. Red and Blue1000 / 思维相关的知识,希望对你有一定的参考价值。


https://codeforces.com/problemset/problem/1469/B
题目的意思就是给了我们两个数组,每一个数组的顺序,在合并后的数组里是不变的。
你会发现俩数组的贡献是没有关系的。
即我们在数组A中取一个最大的前缀和。
B中也去一个最大的前缀和。
输出这两的和即可。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],b[N],n,m,t;
int main(void)
{
	cin>>t;
	while(t--)
	{
		int index1=0,index2=0,ans1=0,ans2=0;
		cin>>n;
		for(int i=0;i<n;i++) cin>>a[i],index1+=a[i],ans1=max(ans1,index1);
		cin>>m;
		for(int i=0;i<m;i++) cin>>b[i],index2+=b[i],ans2=max(ans2,index2);
		cout<<ans1+ans2<<endl;
	}
	return 0;
}

以上是关于B. Red and Blue1000 / 思维的主要内容,如果未能解决你的问题,请参考以下文章

CF #738(div2)B. Mocha and Red and Blue(构造)

Ruby Red and Sky Blue

绘本故事:Ruby Red and Sky Blue

绘本阅读《Ruby Red and Sky Blue》

Ruby Red And Sky Blue

CodeForces - 1519A Red and Blue Beans