1555C - Coin Rows

链接:

https://codeforces.com/problemset/problem/1555/C

题意:

两行的数组,可以在任意位置下移(不回头),和向右,A进过的的地方分数归零,结果以B得分为准

A想让得分最低,B想让得分最高,两人极端聪明,求结果。A先走

在这里插入图片描述

输入

3
3
1 3 7
3 5 1
3
1 3 9
3 5 1
1
4
7

输出量

7
8
0

解:

遍历一遍第一层,算出A在每个点向下后,B能得到的分数(每次两种),求这两种中最大的保存,在遍历的每种情况中取保存数中最小的

实际代码:

#include<iostream>
#include<algorithm>
#include<limits.h>
using namespace std;
typedef long long int ll;
int a[100005];
int b[100005];
int main()
{
	int t;
	cin>>t;
	for(int f=1;f<=t;f++)
	{
		int m;
		cin>>m;
		ll ans=LLONG_MAX;
		ll sums=0,sumx=0;
		for(int i=1;i<=2;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(i==1)
				{
					cin>>a[j];
					sums+=a[j];
				}
				else cin>>b[j];
			}
		}
		for(int i=1;i<=m;i++)
		{
			sums-=a[i];
			ll temps=sums;
			if(i>1) sumx+=b[i-1];
			ll tempx=sumx;
			//cout<<temps<<" "<<tempx<<endl;
			ans=min(ans,max(tempx,temps));
		}
		//cout<<"---"<<endl;
		cout<<ans<<endl;
	}
}

限制:

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值