日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDOJ 3415 Max Sum of Max-K-sub-sequence

發布時間:2023/12/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDOJ 3415 Max Sum of Max-K-sub-sequence 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


單調隊列優化。。。。

Max Sum of Max-K-sub-sequence

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4759????Accepted Submission(s): 1734


Problem DescriptionGiven a circle sequence A[1],A[2],A[3]......A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the right neighbour of A[n] is A[1].
Now your job is to calculate the max sum of a Max-K-sub-sequence. Max-K-sub-sequence means a continuous non-empty sub-sequence which length not exceed K.
InputThe first line of the input contains an integer T(1<=T<=100) which means the number of test cases.?
Then T lines follow, each line starts with two integers N , K(1<=N<=100000 , 1<=K<=N), then N integers followed(all the integers are between -1000 and 1000).
OutputFor each test case, you should output a line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the minimum start position, if still more than one , output the minimum length of them.
Sample Input4
6 3
6 -1 2 -6 5 -5
6 4
6 -1 2 -6 5 -5
6 3
-1 2 -6 5 -5 6
6 6
-1 -1 -1 -1 -1 -1
Sample Output7 1 3
7 1 3
7 6 2
-1 1 1
Authorshǎ崽@HDU
SourceHDOJ Monthly Contest – 2010.06.05
Recommendlcy

#include <iostream>#include <cstdio>#include <cstring>
using namespace std;
int a[411111];int f[411111];int que[1111111];int pt[1111111];int n,k;int T;int head,tail;int sum[411111];int max_sum,start,end;

int main(){scanf("%d",&T);while (T--){memset(f,0,sizeof(f));memset(que,0,sizeof(que));memset(pt,0,sizeof(pt));memset(sum,0,sizeof(sum));scanf("%d%d",&n,&k);for (int i=1;i<=n;i++){scanf("%d",&a);a[i+n]=a;}for (int i=1;i<=n+k;i++){sum+=sum[i-1]+a;}
head=tail=0;max_sum=start=end=-1e9; for(int i=1;i<=n+k;i++)? ? ? ? {? ? ? ? ? ? while(head<tail&&i-pt[head]>k) ?head++;? ? ? ? ? ? while(head<tail&&sum[i-1]<que[tail-1]) tail--;
? ? ? ? ? ? que[tail]=sum[i-1]; pt[tail++]=i-1;
? ? ? ? ? ? f=sum-que[head];
? ? ? ? ? ? if(max_sum<f)? ? ? ? ? ? {? ? ? ? ? ? ? ? max_sum=f;? ? ? ? ? ? ? ? start=pt[head]+1;? ? ? ? ? ? ? ? end=i;? ? ? ? ? ? }? ? ? ? }
if(start>n) start-=n;if(end>n) end-=n;
printf("%d %d %d\n",max_sum,start,end);
}return 0;}

轉載于:https://www.cnblogs.com/CKboss/p/3350984.html

總結

以上是生活随笔為你收集整理的HDOJ 3415 Max Sum of Max-K-sub-sequence的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。