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.

 
Codeforces Round #223 (Div. 2)
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
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;
}

Codeforces Round #223 (Div. 2) A的更多相关文章

  1. Codeforces Round #223 (Div. 2) E. Sereja and Brackets 线段树区间合并

    题目链接:http://codeforces.com/contest/381/problem/E  E. Sereja and Brackets time limit per test 1 secon ...

  2. Codeforces Round #223 (Div. 2) C

    C. Sereja and Prefixes time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #223 (Div. 2)--A. Sereja and Dima

    Sereja and Dima time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #633 (Div. 2)

    Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3& ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. Java自带工具jstack故障分析的一个案例

    公司的一个web应用项目运行了很长一段时间,达半年之久,前段时间突然出现了服务不可用的情况,所有的请求都不可达,服务彻底挂了.查看tomcat进程还在,cpu使用率低,一时没找着问题,重启了服务.过了 ...

  2. linux crontab 实现每秒执行(转)

    linux crontab 命令,最小的执行时间是一分钟.如需要在小于一分钟内重复执行,可以有两个方法实现. 1.使用延时来实现每N秒执行 创建一个php做执行动作,非常简单,就是把当前时间写入log ...

  3. HTML 元素

    HTML 文档是由 HTML 元素定义的. HTML 元素 HTML 元素指的是从开始标签(start tag)到结束标签(end tag)的所有代码. 开始标签 元素内容 结束标签 <p> ...

  4. 一个平时写程序通用的Makefile样例

    //需要目标名和程序名字相同 .PHONY:clean all //伪目标 CC=gcc CFLAGS=-Wall -g BIN= //目标 all:$(BIN) %.o:%.c $(CC) $(CF ...

  5. mui中的关闭页面的几种方法

    一.总结: mui中关闭当前页面的几种方式: 1.swipeBack(暂未测试过) 2.keyEventBind(暂未测试过) 3.给标签的class加.mui-action-back(返回的是前一个 ...

  6. byte[] 与字符串转换

    //取值之后进行 StringBuffer buffer=new StringBuffer(); for (int i = 0; i < enBytes.length; i++) { if(i! ...

  7. CXF发布restful WebService的入门例子(客户端)

    上篇说了怎么用cxf发布restful webservice,由于浏览器只能对该service发送http的GET请求,所以如果想对服务器上的数据,还需要实现客户端. 客户端的实现方式有无数种...可 ...

  8. 分析MySQL慢日志(转)

    使用 MySQL自带命令 mysqldumpslow 查看 OPTIONS -s ORDER ORDER, 主要有 c, t, l, r 和 ac, at, al, ar, 分别是按照 query次数 ...

  9. SQL中CONVERT()转化函数的用法 字符串转日期

    SELECT CONVERT(varchar(), GETDATE(), ): :57AM SELECT CONVERT(varchar(), GETDATE(), ): // SELECT CONV ...

  10. eclipse 中的注释 快捷键-添加/* */注释-Ctrl+Shift+/

    (4)Ctrl+Shift+/ 说明:添加/* */注释 (5)Ctrl+Shift+\ 说明:消除/* */注释 更多:http://blog.csdn.net/wjeson/article/det ...