#P1877. [HAOI2012] 音量调节

    ID: 829 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>动态规划,dp2012河南各省省选枚举,暴力背包

[HAOI2012] 音量调节

Description

A guitarist is preparing for a performance. He does not like to use the same volume throughout the show, so he decides that before each song he will change the volume once. Before the show starts, he makes a list that records by how much he wants to change the volume before each song. Each time he changes the volume, he can either turn it up or turn it down.

The volume is described by an integer. In the input, the integer beginLevelbeginLevel represents the guitar’s initial volume, and the integer maxLevelmaxLevel represents the guitar’s maximum volume. The volume cannot be less than 00 or greater than maxLevelmaxLevel. The input also gives nn integers c1,c2,c3,,cnc_1,c_2,c_3,\cdots,c_n, which means that before the ii-th song begins, the guitarist wants to change the volume by that amount.

The guitarist wants to play the last song at the highest possible volume; your task is to find that maximum volume.

Input Format

The first line contains three integers nn, beginLevelbeginLevel and maxLevelmaxLevel.

The second line contains nn integers c1,c2,c3,,cnc_1,c_2,c_3,\cdots,c_n.

Output Format

Output the maximum possible volume for the last song. If the guitarist cannot avoid the volume going below 00 or above maxLevelmaxLevel, output -1.

3 5 10
5 3 7

10

Hint

1n501\le n\le 50, 1cimaxLevel1\le c_i\le maxLevel, 1maxLevel10001\le maxLevel\le 1000, 0beginLevelmaxLevel0\le beginLevel\le maxLevel.

Translated by ChatGPT 5