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

Game on array

Time limit: 1000 ms
Memory limit: 256 MB
You are playing a game with array $A$ of $n$ integers consisting of only 3 values $-1, 0, 1$. You can choose an arbitrary integer in the range $[1, n]$ and your score the larger one of the 2 following expressions: $$(A_1 + A_2 + ... + A_i) \times (-1) + (A_{i + 1} + ... + A_n)$$ or $$(A_1 + A_2 + ... + A_i) + (A_{i + 1} + ... + A_n) \times (-1) $$ Find a way to achieve maximum score. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $A_i$. ### Output - Maximum possible score. ### Constraints - $1 \le n \le 10^5$. - $A_i \in \\{-1, 0, 1\\}$. ### Example Input: ``` 4 1 1 1 -1 ``` Output: ``` 4 ```
Introduction to Prefix sum
Prefix sum
Maximum subarray sum
Balance substring
Divisible by d
Subarray sum
Game on array
2D prefix sum
Stair query
Maximum sum subarray 2
Average
Ratio Substrings
Maximum submatrix sum
Maximum subarray sum 3
Manhattan distance
Minimum distance
Topic
Prefix sum
Rating 800
Source USACO
Solution (0) Solution