B. Red and Blue
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
Monocarp had a sequence aa consisting of n+mn+m integers a1,a2,…,an+ma1,a2,…,an+m. He painted the elements into two colors, red and blue; nn elements were painted red, all other mm elements were painted blue.
After painting the elements, he has written two sequences r1,r2,…,rnr1,r2,…,rn and b1,b2,…,bmb1,b2,…,bm. The sequence rr consisted of all red elements of aa in the order they appeared in aa; similarly, the sequence bb consisted of all blue elements of aa in the order they appeared in aa as well.
Unfortunately, the original sequence was lost, and Monocarp only has the sequences rr and bb. He wants to restore the original sequence. In case there are multiple ways to restore it, he wants to choose a way to restore that maximizes the value of
f(a)=max(0,a1,(a1+a2),(a1+a2+a3),…,(a1+a2+a3+⋯+an+m))f(a)=max(0,a1,(a1+a2),(a1+a2+a3),…,(a1+a2+a3+⋯+an+m))
Help Monocarp to calculate the maximum possible value of f(a)f(a).
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Then the test cases follow. Each test case consists of four lines.
The first line of each test case contains one integer nn (1≤n≤1001≤n≤100).
The second line contains nn integers r1,r2,…,rnr1,r2,…,rn (−100≤ri≤100−100≤ri≤100).
The third line contains one integer mm (1≤m≤1001≤m≤100).
The fourth line contains mm integers b1,b2,…,bmb1,b2,…,bm (−100≤bi≤100−100≤bi≤100).
Output
For each test case, print one integer — the maximum possible value of f(a)f(a).
Example
input
Copy
4 4 6 -5 7 -3 3 2 3 -4 2 1 1 4 10 -3 2 2 5 -1 -2 -3 -4 -5 5 -1 -2 -3 -4 -5 1 0 1 0
output
Copy
13 13 0 0
Note
In the explanations for the sample test cases, red elements are marked as bold.
In the first test case, one of the possible sequences aa is [6,2,−5,3,7,−3,−4][6,2,−5,3,7,−3,−4].
In the second test case, one of the possible sequences aa is [10,1,−3,1,2,2][10,1,−3,1,2,2].
In the third test case, one of the possible sequences aa is [−1,−1,−2,−3,−2,−4,−5,−3,−4,−5][−1,−1,−2,−3,−2,−4,−5,−3,−4,−5].
In the fourth test case, one of the possible sequences aa is [0,0][0,0].
解题说明:水题,可以分别求出两组数中和最大的数列,然后求和。
#include<stdio.h>int main()
{int t;scanf("%d", &t);while (t--){int n, m, i, s1 = 0, s2 = 0, s1m = 0, x, s2m = 0;scanf("%d", &n);for (i = 0; i<n; i++){scanf("%d", &x);s1 += x;s1m = s1m>s1 ? s1m : s1;}scanf("%d", &m);for (i = 0; i<m; i++){scanf("%d", &x);s2 += x;s2m = s2m>s2 ? s2m : s2;}printf("%d\n", s1m + s2m);}return 0;
}
B. Red and Blue相关推荐
- AC日记——Red and Blue Balls codeforces 399b
399B - Red and Blue Balls 思路: 惊讶的发现,所有的蓝球的消除都是独立的: 对于在栈中深度为i的蓝球消除需要2^i次操作: 代码: #include <cstdio&g ...
- CF #738(div2)B. Mocha and Red and Blue(构造)
problem B. Mocha and Red and Blue time limit per test1 second memory limit per test256 megabytes inp ...
- Mocha and Red and Blue 模拟字符串
题意 : 由'?' 'B' 'R'组成的字符串,将所有'?'变成'B'或者'R',要求出现'BB'和'RR'数量最少,求最终字符串. 思路 : 找到第一个不是'?'的字符(这里有一个注意点,全是'?' ...
- A. Red and Blue Beans
题意:红豆子和绿豆子分在不同的篮子里.问最小的最大差是能不能比给的d小. 方法:尽可能用更多的篮子里. #include<iostream> using namespace std; in ...
- A. Red Versus Blue
https://codeforces.com/contest/1659/problem/A input 3 7 4 3 6 5 1 19 13 6 output RBRBRBR RRRBRR RRBR ...
- Python 笔试面试及常用技巧 (1)
1. 交换两个数字 In [66]: x, y = 1, 2In [67]: x Out[67]: 1In [68]: y Out[68]: 2 赋值的右侧形成了一个新的元组,左侧立即解析(unpac ...
- 3 用python进行OpenCV实战之画图(直线,矩形,圆形)
前言 在上一节我们通过使用NumPy的数组分割成功的在我们的图像上画了一个绿色的方块,但是如果我们想画一个单一的线条或者圆圈该怎么办呢?NumPy没有提供相关的功能,但是OpenCV提供了相关的函数, ...
- 2 用python进行OpenCV实战之图像基本知识
前言 在这一节,我们将学习图像的基本构成单元--像素,我们将详细的探讨什么是像素?像素是如何使用来构成图像的?然后学习如何通过OpenCV来获取和操纵像素. 1 什么是像素 所有的图像都包含一组像素, ...
- dataframe,python,numpy 问题索引1
# 找出只有赌场数据的账户 gp=data.groupby(['查询账号','场景标签'],as_index=True) tj=gp.size().reset_index()按查询账号和场景标签分组并 ...
最新文章
- HashSet中的add()方法( 三 )(详尽版)
- WinXp安装Oracle 11g Express Edition
- Java中switch都可以支持哪些数据类型
- mycat快速体验(转)
- C++ protobuf 不仅仅是序列化……
- Selenium IDE安装和检查获取的控件路径技巧
- 《精通移动app测试实战:技术、工具和案例》新书上市
- [蓝桥杯2018初赛]乘积尾零-数论
- web前端知识点太多_web前端常见知识点
- Docker学习总结(48)——Docker 四种网络模式温故
- 在同一个公司死磕5-10年,到底值不值得?
- 登录处理php页面,登录处理页面
- 杰瑞·卡普兰:人工智能并不可怕 未来将带来两大影响
- 利用zui上传excel文件,并通过java后台读取excel中的内容
- springtboot 操作es
- 高德导航是用的北斗卫星吗?
- 拯救脆弱的智慧城市:不但要“智商” 还得有“生气”
- 安装Phoenix时,执行./splline.py报错File “./sqlline.py“, line 25, in <module> import phoenix_utils File
- [Codeforces Round #627]1324D - Pair of Topics[二分]
- cmd.exe专杀工具