Ketu and Petu
All submissions for this problem are available.Chef saw Ketu and Petu playing the following game. - There are $n$ cards placed in a line on a table with each card having a value on it. Card $i$ has value $C_i$, where $1 \leq i \leq n$. Initially, $C_1$ is at the front and $C_n$ is at the back. - Both of them take their turn alternately with Petu starting the game. - Petu draws card from the front of the remaining cards. - Ketu draws card from the back of the remaining cards. - Both of them gain value written on the card they drew. - When there is no card remaining, the game ends. Chef was wondering what will be difference in points earned by Ketu and Petu after the game ends? ###Input: - The first line of input contains a single number $n$. - The second line of input contains $n$ space seperated integers $C_1, C_2, \dots, C_n$. ###Output: Print a single integer, Ketu's points - Petu's points after the end of the game. ###Constraints: - $1 \leq n \leq 10^5$ - $1 \leq C_i \leq 10^3$ for each valid $i$ ###Sample Input: ``` 3 1 4 10 ``` ###Sample Output: ``` 5 ``` ###Explanation: Let $K$ be points of Ketu and $P$ be points of Petu. - Initially, $K = 0$ and $P = 0$. - Petu draws card with value $1$ and gains $1$ points. So, $P = 0 + 1 = 1$. - Ketu draws card with value $10$ and gains $10$ points. So, $K = 0 + 10 = 10$. - Petu draws card with value $4$ and gains $4$ points. So, $P = 1 + 4 = 5$. Hence, the value of $K - P = 10 - 5 = 5$.
|Tags||chirag11032000, keteki, kpm22019|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions