mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1003_mtry.cpp
From http://www.cnblogs.com/zhourongqing/archive/2012/04/08/2438202.html
This commit is contained in:
parent
f7453e45b4
commit
9ef40eb7b5
40
HDOJ/1003_mtry.cpp
Normal file
40
HDOJ/1003_mtry.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user