codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

859C.md (2027B)


      1 Source: https://codeforces.com/problemset/problem/859/C
      2 
      3 C. Pie Rules
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
     22 
     23 The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
     24 
     25 All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
     26 
     27 Input
     28 
     29 Input will begin with an integer *N* (1 ≤ *N* ≤ 50), the number of slices of pie.
     30 
     31 Following this is a line with *N* integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
     32 
     33 Output
     34 
     35 Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3  
     43 141 592 653
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 653 733
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 5  
     56 10 21 10 21 10
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 31 41
     63 ```
     64 
     65 Note
     66 
     67 In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.