#P10709. [NOISG 2024 Prelim] Party

    ID: 12199 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学贪心2024排序NOISG(新加坡)

[NOISG 2024 Prelim] Party

Background

Translated from NOI SG 2024 Prelim B.Party

Problem Description

James has nn friends, and he wants to choose 00 or more of them to attend his party. If the ii-th friend attends his party, it will produce aia_i points of happiness. Note: some friends do not want to attend the party, so their aia_i will be negative.

However, his home only has a single row of nn seats, and because of social distancing, two people cannot sit in adjacent seats. Now James wants to know: if he invites friends in the best way, what is the maximum possible sum of happiness values of the invited friends.

Input Format

The first line contains an integer nn.

The second line contains nn integers, representing aa.

Output Format

One line with one integer, representing the answer.

5
3 2 -1 4 5
12
1
10
10
6
1 -3 2 10 -4 9
21

Hint

Sample #1 Explanation

James can invite friends 1,4,51,4,5.

Sample #2 Explanation

James can invite the only friend.

Sample #3 Explanation

James can invite friends 3,4,63,4,6.

Constraints

Subtask\text{Subtask} Score Special Property
00 Samples
11 4949 n3n\le 3
22 3838 n1000n\le 1000
33 1313 None

For 100%100\% of the testdata, 1n2×105,109ai1091 \le n \le 2 \times 10^5,-10^9 \le a_i \le 10^9.

Translated by ChatGPT 5