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. JSP的Servlet监听器

    JSP的Servlet监听器 来源: http://blog.csdn.net/phoenix_17th/article/details/3868670 Servlet 监听器用于监听一些重要事件的发 ...

  2. jQuery图片无缝滚动JS代码ul/li结构

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. JDBC Driver

    Infomix Driver: com.informix.jdbc.IfxDriver JDBC URL : jdbc:informix-sqli://<host>:<port> ...

  4. js 图片切换效果

    效果如下: 代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&quo ...

  5. 批处理安装APK

    set adbpa=D:\Nexus6\ota51\ADBTool set apkpa=D:\WDJDownload\Apps %adbpa%\adb.exe install %apkpa%\CPU- ...

  6. 【转】Java集合框架综述

    文章目录 1. 集合框架(collections framework) 2. 设计理念 3. 两大基类Collection与Map 3.1. Collection 3.2. Map 4. 集合的实现( ...

  7. 【转】JDBC为什么要使用PreparedStatement而不是Statement

    http://www.importnew.com/5006.html PreparedStatement是用来执行SQL查询语句的API之一,Java提供了 Statement.PreparedSta ...

  8. IntelliJ IDEA中怎么查看方法说明?

    View→Quick Documentation 查看当前配置的快捷键(例如Ctrl + Q) 在光标所在的方法上按下快捷键就可以看到方法的说明 下图为在View菜单中查看当前配置的快捷键截图: 下图 ...

  9. LVS包转发模型和调度算法(转)

    LVS简介 Internet的快速增长使多媒体网络服务器面对的访问数量快速增加,服务器需要具备提供大量并发访问服务的能力,因此对于大负载的服务器来 讲, CPU.I/O处理能力很快会成为瓶颈.由于单台 ...

  10. C语言每日一题之No.12

    文件操作知识:如何将一个文件的内容读取到另一个文件里? fread函数和fwrite函数   1.函数功能   用来读写一个数据块. 2.一般调用形式   fread(buffer,count,siz ...