CF381A.Sereja and Dima

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.

Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.

Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.

谢列亚和迪马正在玩一个游戏。游戏规则非常简单:两名玩家面前有一排 nn 张卡片,每张卡片上写有一个数字,且所有卡片上的数字互不相同。两名玩家轮流行动,谢列亚先手。在自己的回合中,一名玩家可以取走一张卡片:要么取走当前最左边的一张,要么取走最右边的一张。当所有卡片都被取完时,游戏结束。游戏结束时,手中卡片数字之和较大的玩家获胜。

谢列亚和迪马都是贪婪的玩家。在自己的回合中,他们总是选择两张可选卡片(即当前最左和最右的卡片)中数字较大的那一张。

因娜是谢列亚和迪马的朋友。她知道两人所采用的这种策略,因此希望根据游戏初始状态,计算出最终的得分。请帮助她。

输入格式

The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.

第一行包含一个整数 nn(1≤n≤10001 \leq n \leq 1000)—— 表格上卡片的数量。
第二行包含从左到右以空格分隔的卡片上的数字。卡片上的数字是 11 到 10001000 之间的互不相同的整数。

输出格式

On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.

在一行中输出两个整数:第一个数为 Sereja 在游戏结束时的得分,第二个数为 Dima 在游戏结束时的得分。

输入输出样例

  • 输入#1

    4
    4 1 2 10

    输出#1

    12 5
  • 输入#2

    7
    1 2 3 4 5 6 7

    输出#2

    16 12

说明/提示

In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.

在第一个样例中,Sereja 将取走编号为 10 和 2 的卡片,因此 Sereja 的总和为 12;Dima 将取走编号为 4 和 1 的卡片,因此 Dima 的总和为 5。

输入解题思路,AI测评打分。不知道怎么写?

首页