1657: [Usaco2006 mar]mooo cow's song

Source: Internet
Author: User

1657: [Usaco2006 mar]mooo cow's song time Limit:5 Sec Memory limit:64 MB
submit:526 solved:365
[Submit] [Status] Description

Farmer John ' s n (1 <= n <= 50,000) cows is standing in a very straight row and mooing. Each cow have a unique height h in the range 1..2,000,000,000 nanometers (FJ really are a stickler for precision). Each cow Moos at some volume V in the range 1..10,000. This "moo" travels across the row of cows in both directions (except for the end cows, obviously). Curiously, it is heard only by the closest cow a direction whose height is strictly larger than that of the mooing C ow (so each moo would be heard by 0, 1 or 2 other cows, depending on not whether or taller cows exist to the mooing cow ' s R Ight or left). The total Moo volume heard by given cow are the sum of all the Moo volumes V for all cows whose mooing reaches the cow. Since some (presumably taller) cows might be subjected to a very large moo volume, FJ wants to buy earmuffs for the cow wh OSE hearing is the most threatened. Please compute the loudest moo volume heard by any cow.

Farmer John's N (1<=n<=50,000) cows stood neatly in a row of "howling". Each cow has a definite height of H (1<=h<=2000000000), called the volume of V (1<=v<=10000). Each cow's cry spreads to both ends, but in each direction it is only heard by the nearest cow whose height is strictly greater than it, so each call is only heard by the 0,1,2 cow (depending on whether there is a cow higher on either side). The total volume that a cow hears is the sum of all the volume it hears. Since some cows have suffered a huge volume, Farmer John is going to buy an ear mask for the most maimed cows, and ask you to help him calculate the maximum total volume.

Input

* Line 1: A single integer, N.

* Lines 2..n+1:line i+1 contains II space-separated integers, H and V, for the cow standing at location I.

Line 1th: A positive integer n.

2nd to n+1: Each line consists of 2 integers separated by spaces representing the height of the cow standing in the first position of the team and the volume of her singing.

Output

* Line 1:the Loudest moo volume heard by any single cow.

The highest total volume that a cow in a team can hear.

Sample INPUT3
4 2
3 5
6 10

INPUT DETAILS:

Three cows:the first one has a height 4 and Moos with Volume 2, etc.
Sample Output7
HINT

The 3rd cow in the team could hear the song of the 1th and 2nd cows, so the total volume she could hear was 2+5=7. Although she sang at the volume of 10, but no cows can hear her singing.

Source

Silver

Solution: Meng Meng da i bright this problem super spirit Bzoj1660, this problem or straight line tree maintenance can, method similar to bzoj1660 (say today only found bzoj1660 inside the b array is useless to ah hehe ... )

1 var2 I,j,k,l,m,n:longint;3A,b,c,e:Array[0..500000] ofLongint;4 functionMax (x,y:longint): Longint;5          begin6               ifX>y ThenMax:=xElsemax:=y;7          End;8 functionmin (x,y:longint): Longint;9          beginTen               ifX<y ThenMin:=xElsemin:=y; One          End; A procedurebuild (x,y,z:longint); -           begin -                if(x=y) Then the                   begin -a[z]:=C[x]; -b[z]:=x; -                   End +                Else -                    begin +Build (x, (X+y)Div 2, z*2); ABuild ((X+y)Div 2+1, y,z*2+1); atA[z]:=max (a[z*2],a[z*2+1]); -                    End; -           End; - functionGetRight (x,y,z,l,r,t:longint): Longint; -          var - I,j,k:longint; in          begin -               ifL>r ThenExit (-1); to               ifC[l]>t Thenexit (l); +               ifA[z]<=t ThenExit (-1); -               if(L=R)or(x=y) ThenExit (-1); the  *I:=getright (x, (X+y)Div 2, z*2, L,min (R, (x+y)Div 2), t); $               ifi=-1  ThenPanax NotoginsengGetright:=getright ((x+y)Div 2+1, y,z*2+1, Max (L, (x+y)Div 2+1), r,t) -               Else thegetright:=i; +          End; A functionGetLeft (x,y,z,l,r,t:longint): Longint; the          var + I,j,k:longint; -          begin $               ifL>r ThenExit (-1); $               ifA[z]<=t ThenExit (-1); -               ifC[r]>t Thenexit (R); -               if(x=y)or(L=R) ThenExit (-1); the  -I:=getleft ((x+y)Div 2+1, y,z*2+1, Max (L, (x+y)Div 2+1), r,t);Wuyi               ifi=-1  Then theGetleft:=getleft (x, (X+y)Div 2, z*2, L,min (R, (x+y)Div 2), T) -               Else Wugetleft:=i; -          End; About begin $ READLN (n); -       fori:=1  toN Do - readln (C[i],e[i]); -Build1N1); AFillchar (b,sizeof (b),0); +       fori:=1  toN Do the          begin -J:=getleft (1N1,1, I-1, C[i]); $K:=getright (1N1, i+1, N,c[i]); the               ifj<>-1  Thenb[j]:=b[j]+E[i]; the               ifk<>-1  Thenb[k]:=b[k]+E[i]; the          End; thel:=0; -       fori:=1  toN Do inl:=Max (l,b[i]); the Writeln (l); the End. About                     

1657: [Usaco2006 mar]mooo cow's song

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.