链接:
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