本來用DP暴力列舉的,竟然沒過……老尷尬了
然后想是不是得哦o(nlog n)或者o(n)
感覺沒什么要講的,代碼簡單
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
int good[3],pre[100001];
int t;
cin>>t;
for(int k=1;k<=t;k++){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&pre[i]);
}
good[0]=pre[1],good[1]=1,good[2]=1;
int temp=0,tpos=1;
for(int i=1;i<=n;i++){
temp+=pre[i];
if(temp>good[0]){
good[2]=i;
good[1]=tpos;
good[0]=temp;
}
if(temp<0){
temp=0;
tpos=i+1;
}
}
printf("Case %d:\n%d %d %d\n",k,good[0],good[1],good[2]);
if(k!=t)
printf("\n");
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/61732.html
標籤:C++
上一篇:母牛的故事
