C. Four Segments

Codeforces
IDCF846C
Time1000ms
Memory256MB
Difficulty
brute forcedata structuresdp
You are given an array of _n_ integer numbers. Let _sum_(_l_, _r_) be the sum of all numbers on positions from _l_ to _r_ non-inclusive (_l_\-th element is counted, _r_\-th element is not counted). For indices _l_ and _r_ holds 0 ≤ _l_ ≤ _r_ ≤ _n_. Indices in array are numbered from 0. For example, if _a_ = \[ - 5, 3, 9, 4\], then _sum_(0, 1) =  - 5, _sum_(0, 2) =  - 2, _sum_(1, 4) = 16 and _sum_(_i_, _i_) = 0 for each _i_ from 0 to 4. Choose the indices of three delimiters _delim_0, _delim_1, _delim_2 (0 ≤ _delim_0 ≤ _delim_1 ≤ _delim_2 ≤ _n_) and divide the array in such a way that the value of _res_ = _sum_(0, _delim_0) - _sum_(_delim_0, _delim_1) + _sum_(_delim_1, _delim_2) - _sum_(_delim_2, _n_) is maximal. Note that some of the expressions _sum_(_l_, _r_) can correspond to empty segments (if _l_ = _r_ for some segment). ## Input The first line contains one integer number _n_ (1 ≤ _n_ ≤ 5000). The second line contains _n_ numbers _a_0, _a_1, ..., _a__n_ - 1 ( - 109 ≤ _a__i_ ≤ 109). ## Output Choose three indices so that the value of _res_ is maximal. If there are multiple answers, print any of them. [samples]
Samples
Input #1
3
-1 2 3
Output #1
0 1 3
Input #2
4
0 0 -1 0
Output #2
0 0 0
Input #3
1
10000
Output #3
1 1 1
API Response (JSON)
{
  "problem": {
    "name": "C. Four Segments",
    "description": {
      "content": "You are given an array of _n_ integer numbers. Let _sum_(_l_, _r_) be the sum of all numbers on positions from _l_ to _r_ non-inclusive (_l_\\-th element is counted, _r_\\-th element is not counted). Fo",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF846C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given an array of _n_ integer numbers. Let _sum_(_l_, _r_) be the sum of all numbers on positions from _l_ to _r_ non-inclusive (_l_\\-th element is counted, _r_\\-th element is not counted). Fo...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments