Title Description
A guitarist is ready to take part in a show. He doesn't like to always use the same volume when performing, so he needs to change the volume before he decides on each song. Before the show began, he had made a list of what volume he wanted to change before each song began. Every time you change the volume, he can choose to turn it up or down.
The volume is described by an integer. The integer beginlevel in the input file, representing the first volume of the guitar, the integer Maxlevel, which represents the maximum volume of the guitar. The volume cannot be less than 0 and cannot be greater than maxlevel. An n integer c1,c2,c3,..., cn is given in the input, indicating how much the guitarist wants to change before the first song starts.
The guitarist wants to play the last song at maximum volume, and your task is to find out what the maximum volume is.
Input/output format
Input format:
The first line is followed by three integers n, beginlevel, Maxlevel.
The second line, in turn, is n integers c1,c2,c3,..., cn.
Data size:
1<=n<=50, 1<=ci<=maxlevel, 1<=maxlevel<=1000, 0<=beginlevel<=maxlevel
Output format:
Output the maximum volume of the last song played. If the guitarist cannot avoid the volume below 0 or higher than maxlevel, output-1.
Input and Output Sample input example # #:
3 5 105) 3 7
Sample # # of output:
10
2 of the 50 times will be over time, 50*1000 not.
The code is actually:
1#include <cstdio>2 intN,k,b,a;3 intv[ -][1010];4 intMain () {5scanf"%d%d%d",&n,&k,&b);6++v[0][k];7 for(intI=1; i<=n;i++){8scanf"%d",&a);9 for(intj=0; j<=b;j++){Ten if(!v[i-1][J])Continue; One if(j+a<=b) ++v[i][j+a]; A if(j-a>=0) ++v[i][j-a]; - } - } the for(inti=b;i>=-1; i--){ - if(i==-1) printf ("-1\n"); - if(V[n][i]) {printf ("%d\n", i);return 0;} - } + return 0; -}
Of course it can be faster, lazy have to fight ~
[HAOI2012] Volume adjustment