Codeforces Round #223 (Div. 2) A
A. Sereja and Dima
1 second
256 megabytes
standard input
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.
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.
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.
4
4 1 2 10
12 5
7
1 2 3 4 5 6 7
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.
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的更多相关文章
- 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 ...
- Codeforces Round #223 (Div. 2) C
C. Sereja and Prefixes time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 ...
- Codeforces Round #633 (Div. 2)
Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3& ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- HBase(三): Azure HDInsigt HBase表数据导入本地HBase
目录: hdfs 命令操作本地 hbase Azure HDInsight HBase表数据导入本地 hbase hdfs命令操作本地hbase: 参见 HDP2.4安装(五):集群及组件安装 , ...
- [转]使用eclipse+pydev远程调试OpenStack
作者:张华 发表于:2014-01-17版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) 1, ...
- SPOJ #4 Transform the Expression
Not hard to know it is simply transform from in-order to post-order.My first idea is to build a tree ...
- 黄聪:WordPress 多站点建站教程(五):获取子站点用户信息(通过输入站点ID号来获取该站点的所有用户)
得到站点ID为1的用户 <ul> <?php $blogusers = get_users('blog_id=1'); foreach ($blogusers as $user) { ...
- fork()详解
参照: http://blog.csdn.net/jason314/article/details/5640969 http://coolshell.cn/articles/7965.html
- Maven实战
一.不要重复造轮子 极限编程(XP)是近些年在软件行业红的发紫的敏捷开发方法,强调拥抱变化. Maven帮助XP团队实现一些核心价值: 1.简单.Maven暴露了一组一致.简洁的操 ...
- Scala第三章学习笔记
换行后的左大括号造成的问题: class FooHolder { def foo() { println("foo was called") } } Scala认为def foo( ...
- ADF_ADF Faces系列6_ADF数据可视化组件简介之建立Thematic Map Component
2013-05-01 Created By BaoXinjian
- PLSQL_Database Link的基本概念和用法(概念)
2014-06-08 Created By BaoXinjian
- HDU 2087 剪花布条(KMP,不可重叠重复子串)
给KMP传的数组一定要从0开始!! 显然,我们要先把模式串放到前面,之后主串放后面,中间隔开,这样就可以根据前缀数组的性质来求了. 这题和我上一篇博客类似,只不过不可重叠,我看了数据范围不大,所以就开 ...