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 ...
随机推荐
- PhoneGap原理分析
PhoneGap提供了Native Api的支持(如:重力感应.相机.联系人.文件.地址位置…), 比如要用js获取本机的联系人,可以用: var options = new ContactFindO ...
- Hibernate入门学习(二)
本文主要讲如何搭建Hibernate开发环境和简单实例. 一.搭建开发测试环境 1.1 下载Hibernate 从Hibernate官方网站上下载最新的Hibernate ORM,从Hibernate ...
- 【转】双机高可用、负载均衡、MySQL(读写分离、主从自动切换)架构设计
架构简介 前几天网友来信说帮忙实现这样一个架构:只有两台机器,需要实现其中一台死机之后另一台能接管这台机器的服务,并且在两台机器正常服务时,两台机器都能用上.于是设计了如下的架构.此架构主要是由kee ...
- MongoDB小型文档型数据库使用
MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中 ...
- TextBox(只允许输入字母或者数字)
实现如下: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System ...
- elixir学习
安装 brew install elixir atom配置 language-elixir atom-elixir elixir的shell iex :erlang.system_info(:otp_ ...
- [cmd]linux 常用命令
1. 磁盘/文件大小中占用情况 df -h: 磁盘大小占用情况 du -h file: 文件夹大小,du -ah file文件夹内所有文件占用情况 du -sh dir: 可以查看文件夹大小,而不列出 ...
- 154 Find Minimum in Rotated Sorted Array II
多写限制条件可以加快调试速度. ======= Follow up for "Find Minimum in Rotated Sorted Array":What if dupli ...
- 黄聪:chrome扩展开发《AJAX请求》
chrome在一次更新之后,出于安全考虑,完全的禁止了content_script从https向http发起ajax请求,即使正常情况下也会在console里给出提示.这对于WEB来讲是好事,但对于扩 ...
- ADF_Database Develop系列3_通过UML进行数据库开发之将Database Diagram转为Class Diagram
2013-05-01 Created By BaoXinjian