Create 1003_mtry.cpp

From http://www.cnblogs.com/zhourongqing/archive/2012/04/08/2438202.html
This commit is contained in:
Kirigaya Kazuto 2016-07-20 19:44:42 +08:00 committed by GitHub
parent f7453e45b4
commit 9ef40eb7b5

40
HDOJ/1003_mtry.cpp Normal file
View File

@ -0,0 +1,40 @@
#include<iostream>
#define N 100010
using namespace std;
int a[N],d[N];
int main()
{
int test,n,i,max,k,f,e;
cin>>test;
k=1;
while(test--)
{
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
d[1]=a[1];
for(i=2;i<=n;i++)
{
if(d[i-1]<0) d[i]=a[i];
else d[i]=d[i-1]+a[i];
}
max=d[1];e=1;
for(i=2;i<=n;i++)
{
if(max<d[i])
{
max=d[i];e=i;
}
}
int t=0;
f=e;
for(i=e;i>0;i--)
{
t=t+a[i];
if(t==max) f=i;
}
cout<<"Case "<<k++<<":"<<endl<<max<<" "<<f<<" "<<e<<endl;
if(test) cout<<endl;
}
return 0;
}