标签:min -- lin names int stream algorithm stdin etc
/*#!/bin/sh
dir=$GEDIT_CURRENT_DOCUMENT_DIR
name=$GEDIT_CURRENT_DOCUMENT_NAME
pre=${name%.*}
g++ -O2 $dir/$name -o $pre -g -Wall -std=c++11
if test $? -eq 0; then
gnome-terminal -x bash -c "time $dir/$pre;echo;read;"
fi*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=2e5+50;
int n,a[maxn],t,k;
int sum[maxn],q[maxn];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<‘0‘||ch>‘9‘){
if(ch==‘-‘)w=-1;ch=getchar();
}
while(ch>=‘0‘&&ch<=‘9‘)s=s*10+ch-‘0‘,ch=getchar();
return s*w;
}
int main(){
freopen("a.in","r",stdin);
t=read();
while(t--){
memset(q,0,sizeof(q));
memset(sum,0,sizeof(sum));
n=read();k=read();
int ans=-INF;
for(int i=1;i<=n;i++)a[i]=read(),sum[i]=sum[i-1]+a[i];
for(int i=n+1;i<=2*n;i++)sum[i]=sum[i-1]+a[i-n];
int head=0,tail=0,l,r;
for(int i=1;i<=k+n;i++){
while(head<tail&&sum[i-1]<sum[q[tail-1]])tail--;
q[tail++]=i-1;
while(head<tail&&i-q[head]>k)head++;
if(sum[i]-sum[q[head]]>ans){
ans=sum[i]-sum[q[head]];
l=q[head]+1;r=i;
}
}
if(l>n)l-=n;
if(r>n)r-=n;
cout<<ans<<" "<<l<<" "<<r<<endl;
}
return 0;
}
标签:min -- lin names int stream algorithm stdin etc
原文地址:https://www.cnblogs.com/614685877--aakennes/p/13125705.html