Codeforces Round #228 (Div. 1) C. Fox and Card Game

Source: Internet
Author: User

The main topic: give you n group number, each group has m, there are two people the first person can only be taken from the beginning, the second person can only take from the last, the first person to start, everyone is smart enough to ask you their final maximum score is how much.

Problem-solving ideas: Obviously if each group can be symmetrical to take the number, will not affect the total score, the impact of the number of odd numbers of those groups, their size has been related to the initiator, the initiator took out the largest, the first take off the big, and so on.

C. Fox and Card Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Fox Ciel is playing a card game with her friend Fox Jiro. There is n piles of cards on the table. And there is a positive an integer on each card.

The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of Any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.

Suppose Ciel and Jiro play optimally, what is the score of the game?

Input

The first line contain an integerN(1?≤? n? ≤?100). Each of the nextNLines contains a description of the pile:the first integer in the si (1?≤? s i? ≤?100)-the number of cards in theI-th pile; Then follow si Positive integers C1 , C2 , ..., ck , ..., Csi (1?≤? C k. ≤?1000)-the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.

Output

Print integers:the sum of Ciel ' s cards and the sum of Jiro ' s cards if they play optimally.

Sample Test (s) input
21 1002 1 10
Output
101 10
Input
19 2 8 6 5 9 4 7 1 3
Output
30 15
Input
33 1 3 23 5 4 62 8 7
Output
18 18
Input
33 1000 1000 10006 1000 1000 1000 1000 1000 10005 1000 1000 1000 1000 1000
Output
7000 7000
Note

In the first example, Ciel'll take the cards with number and 1, Jiro'll take the card with Number 10.

In the second example, Ciel'll take cards with numbers 2, 8, 6, 5, 9 and Jiro would take cards with numbers 4, 7, 1, 3.

#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < stack> #include <ctime> #include <map> #include <set> #define EPS 1e-9///#define M 1000100///#define ll __int64#define ll Long long///#define INF 0x7ffffff#define inf 0x3f3f3f3f#define PI 3.1415926535898#define Zero (x) ((FA BS (x) <eps)? 0:x) #define MOD 1000000007#define Read () freopen ("Autocomplete.in", "R", stdin) #define Write () freopen (" Autocomplete.out "," w ", stdout) #define CIN () Ios::sync_with_stdio (false) using namespace Std;const int maxn = 110;int mp[    Maxn][maxn];int Num[maxn];int Main () {int n;        while (cin >>n) {int lsum = 0;        int rsum = 0;            for (int i = 1; I <= n; i++) {scanf ("%d", &mp[i][0]);   for (int j = 1; J <= Mp[i][0]; j + +) scanf ("%d", &mp[i][j]);     } int ans = 0;            for (int i = 1; I <= n; i++) {int x = MP[I][0]/2;            cout<< "x = =" <<x<<endl;            for (int j = 1; j <= X; j + +) Lsum + = Mp[i][j];                if (mp[i][0]%2) {num[ans++] = mp[i][x+1];            x + +;        } for (int j = x+1; J <= Mp[i][0]; j + +) Rsum + = Mp[i][j];        } sort (num, num+ans);        int cnt = 0;            for (int i = ans-1; I >= 0; i--) {if (cnt%2) rsum + = Num[i];            else lsum + = Num[i];        cnt++;    } cout<<lsum<< "" <<rsum<<endl; }}


Codeforces Round #228 (Div. 1) C. Fox and Card Game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.