博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #223 (Div. 2) A
阅读量:6117 次
发布时间:2019-06-21

本文共 2377 字,大约阅读时间需要 7 分钟。

A. Sereja and Dima

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Sample test(s)
input
4 4 1 2 10
output
12 5
input
7 1 2 3 4 5 6 7
output
16 12
Note

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.

 

 
#include 
#include
#include
#include
#include
#include
using namespace std;class App{ private : int N ; int *num ; int dp[2] ; public : App() ; App(int) ; ~App() ; void read() ; void gao() ;};App::App(int n):N(n){ num = (int *)malloc(N*sizeof(int)) ; dp[0] = dp[1] = 0 ;}App::~App(){ delete []num ;}void App::read(){ for(int i = 0 ; i < N ; i++) scanf("%d",num + i) ;}void App::gao(){ int L = 0 ; int R = N - 1 ; int i = 0 ; while(L <= R){ if(*(num + L) > *(num + R)){ dp[i] += *(num + L) ; L++ ; } else{ dp[i] += *(num + R) ; R-- ; } i^=1 ; } printf("%d %d\n",dp[0],dp[1]) ;}int main(){ int n ; cin>>n ; App *app ; app = new App(n) ; app->read() ; app->gao() ; delete app ; return 0;}

转载于:https://www.cnblogs.com/liyangtianmen/p/3523868.html

你可能感兴趣的文章
glbp详解
查看>>
一个简单好用的zabbix告警信息发送工具
查看>>
彻底解决SysFader:IEXPLORE.EXE应用程序错误
查看>>
正则表达式
查看>>
Unix/Linux下删除Oracle控制文件Controlfile为什么实例Instance没有立即奔溃?
查看>>
泄露门年终盘点:***用户网站间的“罗生门”
查看>>
linux:yum和apt-get的区别
查看>>
Sentinel 1.5.0 正式发布,引入 Reactive 支持
查看>>
如何对网站进行归档
查看>>
数据库之MySQL
查看>>
2019/1/15 批量删除数据库相关数据
查看>>
数据类型的一些方法
查看>>
Mindjet MindManager 2019使用教程:
查看>>
游戏设计的基本构成要素有哪些?
查看>>
详解 CSS 绝对定位
查看>>
AOP
查看>>
我的友情链接
查看>>
打印服务自动停止
查看>>
linux--ab压力测试详解
查看>>
C++模板之typename和class关键字的区别
查看>>