Holidays (Codevs 3622)

Source: Internet
Author: User

Title Description Description

After months of hard work, FJ decided to let the cows have a holiday. Holidays can be in 1 ... N Days of arbitrary selection (need continuous), each day has a enjoy the index W. But the demand of cows is very harsh, the holiday can not be shorter than p days, otherwise the cows can not get enough rest, vacation can not exceed Q days, otherwise the cows will play bored. FJ wants to know the biggest benefits cows can get.

Enter a description Input Description

First line: N,p,q.

Second line: n numbers, separated by a space in the middle.

Output Description Output Description

An integer that the cows can get the maximum enjoyment index.

Sample Input Sample Input

5 2 4

-9-4-3 8-6

Sample Output Sample Output

5

data range and tips Data Size & Hint

50% 1≤n≤10000

100% 1≤n≤100000

1<=p<=q<=n

The index is within the Longint range.

Tips:

Choose 3–4 days and enjoy the index of -3+8=5

/*the 50-point approach is for each s[i], find the smallest s[j] (i-x<=j<=i-y), update the answer. Since this j is within a certain interval, it can be optimized with a monotone queue. */#include<cstdio>#include<iostream>#defineN 100010#defineINF 10000000000000LL#definell Long Longusing namespacestd;ll A[n],s[n],q[n],n,x,y,head=1, tail;intMain () {CIN>>n>>x>>y;  for(LL i=1; i<=n;i++) {ll p;cin>>p; S[i]=s[i-1]+p; } ll ans=-INF;  for(LL i=x;i<=n;i++)    {         while(S[i-x]<s[q[tail]]&&head<=tail) tail--; q[++tail]=i-x;  while(Q[head]<i-y&&head<=tail) head++; Ans=max (ans,s[i]-S[q[head]]); } cout<<ans; return 0;}

Holidays (Codevs 3622)

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.