2748: [HAOI2012] Volume adjustment

Source: Internet
Author: User

2748: [HAOI2012] Volume adjustment time limit:3 Sec Memory limit:128 MB
submit:719 solved:475
[Submit] [Status] Description

A guitarist is ready to take part in a show. He doesn't like to always use the same volume at the show, so he decides to change the volume before each song. Before the show began, he had made a list of what volume he wanted to change before each song started. Every time you change the volume, he can choose to turn it up or down.
The volume is described by an integer. The given integer beginlevel in the input file, representing the volume at the beginning of the guitar, as well as 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 also given in the input file, 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

The first line is followed by three integers: N, beginlevel, Maxlevel.
The second line is n integers in turn: c1,c2,c3.....cn.

Output

Output the maximum volume of the last song played. If the guitarist cannot avoid the volume below 0 or higher than maxlevel, output-1.

Sample Input3 5 10
5 3 7Sample OutputTenHINT

1<=n<=50,1<=ci<=maxlevel 1<=maxlevel<=1000

0<=beginlevel<=maxlevel

Source

The sum: This is the rhythm of today and dp water work = = ... This problem some similar to the past this year Noip (NOIP2014) Flappy Bird that problem, but the situation is much simpler, so it is much easier, the idea is when the time for I, the volume of J, there is no possibility, and then according to the status of the previous moment can be judged, My code is Meng Meng da!!!

1 var

2I,j,k,l,m,n,a1,a2,a3,a4:longint;
3A:Array[0.. -,0.. -] ofLongint;
4begin
5READLN (N,L,M);
6Fillchar (A,sizeof (a),0);
7a[0, l]:=1;
8 fori:=1 toN Do
9begin
Tenk:=0;
OneRead (A1);
A forj:=0 toM Do
-begin
- if(J+A1) <=m Then
thebegin
-ifa[i-1, j+a1]=1 Then
-begin
-a[i,j]:=1;
+k:=1;
-End;
+End;
Aif(J-A1) >=0 Then
atbegin
- ifa[i-1, j-a1]=1 Then
-begin
-a[i,j]:=1;
-k:=1;
- End;
inEnd;
-End;
to ifk=0 Then
+begin
-Writeln (-1);
theHalt
*End;
$End;
Panax Notoginseng forI:=mDownto0 Do
-ifa[n,i]=1 Then
thebegin
+Writeln (i);
AHalt
theEnd;
+End.

2748: [HAOI2012] Volume adjustment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.