标签:problem iostream name stream eof style split int mem
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1003
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; int t,n,k,x=0,a[100001],dp[100001],flag=0; int main() { scanf("%d",&t); while(t--) { if(flag++!=0) printf("\n"); scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); int max=-9999999; memset(dp,0,sizeof(dp)); dp[1]=a[1]; for(int i=2; i<=n; i++) dp[i]=dp[i-1]+a[i]>a[i] ? dp[i-1]+a[i] : a[i]; for(int i=1; i<=n; i++) { if(dp[i]>max) { max=dp[i]; k=i; } } int sum=0,p=0; for(int i=k; i>=1; i--) { sum+=a[i]; if(sum==max) p=i; } printf("Case %d:\n%d %d %d\n",++x,max,p,k); } return 0; }
标签:problem iostream name stream eof style split int mem
原文地址:http://www.cnblogs.com/a-clown/p/5987722.html