report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Game on array - FlandreOJ: Flandre Online Judge

Game on array

Time limit: 1000 ms
Memory limit: 256 MB
Marisa and Reimu are playing a game on an array $A$ of $n$ integers. Starting from Marisa, they take turns performing the following move: - Pick either the first or the last element in array $A$ and remove it. The player gain $x$ points, where $x$ is the previously chosen element. Let $x$ and $y$ are the score of Marisa and Reimu at the end of the game, respectively. Marisa wants to maximize $x-y$ while Reimu wants to minimize $x-y$. Assuming they both play optimally, find the resulting $x-y$. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. ### Output - Print $x-y$. ### Constraints - $1 \le n \le 5000$. - $1 \le A_i \le 10^9$. ### Example Input: ``` 4 10 80 90 30 ``` Output: ``` 10 ```
Introduction to Dynamic Programming (Part two)
Sake game
Coins
Coins 2
Game on array
Longest increasing subsequence 2
Convolution
Regular bracket sequence
Faulty addition
Weird bank
Delete operation
Palindromize
Color ribbon
Unique subsequences
Unique subsequences 2
Cow exhibition
Knapsack 3
Compressing array
Regular bracket sequence 2
Maximum path 3
Concating substring
Soil
Stacking boxes
String transformation
Palindromic quadruple
Finding teammates
Topic
Dynamic Programming
Rating 1100
Source Atcoder
Solution (0) Solution