Super piano (Codevs 2934)

Source: Internet
Author: User

Title Description Description

Small Z is a small famous pianist, recently Dr. C gave a small z a super piano, small z hope to use this piano to create the world's most beautiful music.

The super piano can play n notes, numbered 1 to N. The magic of the I note is AI, where AI can be negative.

A "super chord" consists of a number of consecutive notes that contain no less than L and no more than R. We define the beauty of the Super chord for the sum of the wonderful degrees of all the notes it contains. Two super chords are thought to be the same, when and only if these two super chords contain a set of notes that are the same.

Small Z decided to create a song composed of K super-chords, in order to make the music more beautiful, small z requires that the song is composed of K different super chords. We define the beauty of a piece of music as the sum of the wonderful degrees of all the super chords it contains. Little Z wants to know the maximum amount of music he can create.

Enter a description Input Description

The first line of the input file contains four positive integers n, K, L, R. where n is the number of notes, K is the number of super chords contained in the song, and L and R are the lower and upper limits of the number of notes contained in the Super chord.

Next n rows, each line contains an integer AI, which represents the degree of beauty of each note by number from small to large.

Output description Output Description

The output file has only one integer that represents the maximum value of the melody's beauty.

Sample input Sample Input

4 3 2 3

3

2

-6

8

Sample output Sample Output

11

Data range and Tips Data Size & Hint

0<n<=500000,0<k<=50000

All data meet: -1000≤ai≤1000,1≤l≤r≤n and guarantee there must be a music to meet the requirements.

/*sustainable segment tree + heap*/#include<cstdio>#include<iostream>#include<algorithm>#include<queue>#defineN 500010#defineM 10000010using namespacestd;inta[n],co[n],root[n],used[n],n,m,l,r,cnt;structnode{intSUM,LC,RC;}; Node T[m*4];p riority_queue< pair<int,int> >Q;intRead () {CharC=getchar ();intnum=0, flag=1;  while(c<'0'|| C>'9'){if(c=='-') flag=-1; c=GetChar ();}  while(c>='0'&&c<='9') {num=num*Ten+c-'0'; c=GetChar ();} returnnum*Flag;}intBuildintVintXinty) {    intk=++cnt;t[k].sum=v; T[K].LC=x;t[k].rc=y; returnK;}voidInsertint&root,intPreintLintRintPOS) {Root=build (t[pre].sum+1, t[pre].lc,t[pre].rc); if(L==R)return; intMid= (L+R)/2; if(pos<=mid) Insert (T[ROOT].LC,T[PRE].LC,L,MID,POS); ElseInsert (t[root].rc,t[pre].rc,mid+1, R,pos);}intQueryintXintYintLintRintk) {    if(L==R)returnl; intMid= (L+R)/2; intsum=t[t[y].lc].sum-t[t[x].lc].sum; if(k<=sum)returnquery (T[X].LC,T[Y].LC,L,MID,K); Else returnQuery (t[x].rc,t[y].rc,mid+1, r,k-sum);}intMain () {n=read (); M=read (); L=read (); r=read ();  for(intI=1; i<=n;i++)    {        intx=read (); A[i]=a[i-1]+x; Co[i]=A[i]; } sort (Co+1, co+n+1); intNum=unique (co+1, co+n+1)-co-1;  for(intI=1; i<=n;i++)    {        intPos=lower_bound (co+1, co+num+1, A[i])-Co; Insert (Root[i],root[i-1],1, Num,pos); }     for(intI=1; i+l-1<=n;i++)    {        intl=i+l-1, R=min (i+r-1, N); intLen= (r-l+1);++Used[i]; intPos=query (root[l-1],root[r],1, Num,len); Q.push (Make_pair (Co[pos)-a[i-1],i)); }    Long Longans=0;  for(intI=1; i<=m;i++)    {        intp=Q.top (). Second; Ans+=q.top (). First;q.pop (); intl=p+l-1, R=min (p+r-1, N); intlen=r-l+1; used[p]++; if(used[p]>=len+1)Continue; intPos=query (root[l-1],root[r],1, num,len-used[p]+1); Q.push (Make_pair (Co[pos)-a[p-1],p)); } cout<<ans; return 0;}
View Code

Super piano (Codevs 2934)

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.