C. Coin Rows-Educational Codeforces Round 112 (Rated for Div. 2)

原文链接Problem - 1555C - Codeforces

制作不易,点赞关注

C. Coin Rows

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Alice and Bob are playing a game on a matrix, consisting of 22 rows and mm columns. The cell in the ii-th row in the jj-th column contains ai,jai,j coins in it.

Initially, both Alice and Bob are standing in a cell (1,1)(1,1). They are going to perform a sequence of moves to reach a cell (2,m)(2,m).

The possible moves are:

  • Move right — from some cell (x,y)(x,y) to (x,y+1)(x,y+1);
  • Move down — from some cell (x,y)(x,y) to (x+1,y)(x+1,y).

First, Alice makes all her moves until she reaches (2,m)(2,m). She collects the coins in all cells she visit (including the starting cell).

When Alice finishes, Bob starts his journey. He also performs the moves to reach (2,m)(2,m) and collects the coins in all cells that he visited, but Alice didn't.

The score of the game is the total number of coins Bob collects.

Alice wants to minimize the score. Bob wants to maximize the score. What will the score of the game be if both players play optimally?

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of testcases.

Then the descriptions of tt testcases follow.

The first line of the testcase contains a single integer mm (1≤m≤1051≤m≤105) — the number of columns of the matrix.

The ii-th of the next 22 lines contain mm integers ai,1,ai,2,…,ai,mai,1,ai,2,…,ai,m (1≤ai,j≤1041≤ai,j≤104) — the number of coins in the cell in the ii-th row in the jj-th column of the matrix.

The sum of mm over all testcases doesn't exceed 105105.

Output

For each testcase print a single integer — the score of the game if both players play optimally.

Example

input

Copy

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

output

Copy

7
8
0

Note

The paths for the testcases are shown on the following pictures. Alice's path is depicted in red and Bob's path is depicted in blue.

-------------------------------------------------------------------------------------------------------------------------------

这个题刚开始看真是无从下手,后来仔细观察,一个人只能右走或下走,只有两行,也就是说,在第一行pos位置下移之后,以后就只能右移,所以路径就只有n条。那么每条路径b为了最大化利益,必须走完剩下全部的,显然不可能,他只能走完第一行剩下全部的或者第二行剩下的。所以对于每条路径,b的得分是上下最大值,因为a足够聪明,她会选择一个得分最小的,也就是min

# include<iostream>
# include<stack>
# include<cstring>
# include<math.h>
# include<map>

# include<iomanip>
using namespace std;
typedef long long int ll;
ll sum1[100000+10],sum2[100000+10];


int main( )
{
   int t;
   cin>>t;

   while(t--)
   {
       int n;
       cin>>n;
       int x;

       for(int i=1;i<=n;i++)
       {
          cin>>x;
           sum1[i]=sum1[i-1]+x;

       }

       for(int i=1;i<=n;i++)
       {
           cin>>x;
           sum2[i]=sum2[i-1]+x;

       }
      
       ll ans=99999999999999999;

       for(int i=1;i<=n;i++)
       {

         ans=min(ans,max(sum1[n]-sum1[i],sum2[i-1]));


       }

       cout<<ans<<'\n';
   }


    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值