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

题目链接:Problem - 1555C - Codeforces

Alice and Bob are playing a game on a matrix, consisting of 2 rows and m columns. The cell in the i-th row in thej-th column contains ai,j coins in it.

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

The possible moves are:

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

First, Alice makes all her moves until she reaches (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)) 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?

题意:Alice和bob两个人都从1,1到2, m, a先走1,1的值也是a的,b后走,他们只能向右和向下,因为只有两行,所以a, b只有一次向下走的机会,所以我们只要遍历n列,找出第一行i-n的值和第二行0 - i的值求max在求min就好,如果后面的求值也跑暴力的就相当于O(t * n * n),所以需要用到前缀和将复杂度将为O(t*n)

#include<bits/stdc++.h>
using namespace std;

int arr[5][100005];
long long a[100005];
long long b[100005];

int main(){
	ios::sync_with_stdio(false);
	int t;
	int n;
	cin >> t;
	while(t--){
		cin >> n;
		for(int i = 0; i < 2; i++){
			for(int l = 0; l < n; l++){
				cin >> arr[i][l];
			}
		}
		for(int i = 0; i < n; i++){
			if(i == 0){
				a[i] = arr[0][i];
				b[i] = arr[1][i];
			}else{
				a[i] = a[i - 1] + arr[0][i];
				b[i] = b[i - 1] + arr[1][i];
			}
		}
		long long sum = 100000000005;
		for(int i = 0; i < n; i++){
			long long ans = 0;
			long long cnt = 0;
			ans = a[n - 1] - a[i];
			cnt = b[i] - arr[1][i];
			sum = min(sum, max(ans, cnt));
		}
		cout << sum << endl;
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值