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)