CF223A题Sereja and Dima
来源:互联网 发布:淘宝网开通淘金币活动 编辑:程序博客网 时间:2024/05/21 22:50
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.
44 1 2 10
12 5
71 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.
#include <stdio.h>int main(){ int a[1002], n, i, s1 = 0, s2 = 0, j, k = 1; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%d", &a[i]); } for(i = 0,j=n-1; i<=j; ) { if(k%2==1) { if(a[i]>a[j]) { s1 = s1 + a[i]; i++; } else { s1 = s1 + a[j]; j--; } } else { if(a[i]>a[j]) { s2 = s2 + a[i]; i++; } else { s2 = s2 + a[j]; j--; } } k++; } printf("%d %d\n", s1, s2); return 0;}
- CF223A题Sereja and Dima
- A. Sereja and Dima
- Sereja and Dima
- Sereja and Dima
- codeforces Sereja and Dima 题解
- cf-381A-Sereja and Dima
- codeforces--2014/1/13--A. Sereja and Dima
- Codeforces 381A Sereja and Dima(模拟)
- Codeforces Round #223 (Div. 2)--A. Sereja and Dima
- Codeforces Round #223 (Div. 2)A. Sereja and Dima&&B. Sereja and Stairs
- Codeforces Round #223 (Div. 2)——A. Sereja and Dima
- CF223B题Sereja and Stairs
- codeforce Sereja and Suffixes(简单题)
- A. Dima and Guards 【思维 好题】
- A. Dima and Continuous Line----思维题
- A. Dima and Guards----思维题
- CF. Dima and Sequence
- A. Dima and Friends
- boost库中的智能指针向上转换
- Ubuntu装好后root的密码设置
- jQuery 入门教程(2): 基本语法
- js中null和 document.getElementById("userId")小结
- DevExpress的文本框 只能输入保留2位小数的正数字
- CF223A题Sereja and Dima
- android service被系统回收的解决方法
- 工作记录
- [2014年学习计划之RoR系列] 第二步 – 熟悉Ruby语言 (2/n) Blocks and Iterators (代码块和迭代器)
- warning: incompatible implicit declaration of built-in function 'exit'
- 读《重构》,学习Collections.unmodifiableList()用法
- libevent源代码分析--event_dispatch() (一)
- ApplicationContextAware动态获取spring bean
- HDU 3359高斯消元