Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:晕那里错了吗,帮我看一下,高手们In Reply To:晕那里错了吗,帮我看一下,高手们 Posted by:redbox at 2006-10-02 02:45:30 算法有问题, 8 17 2 2 2 8 1 4 2 1这组数据答案就不对 > #include <stdio.h> > > int main(void) > { > int buffer[100000]; > _int64 n,m,sum,temp; > int i,t; > scanf("%I64d %I64d",&n,&m); > for(i=0;i<n;i++) > { > scanf("%d",&buffer[i]); > } > sum=0; > t=buffer[0]; > temp=0; > for(i=0;i<n;i++) > { > > if(temp+buffer[i]<=m && buffer[i]<=t) > { > temp+=buffer[i]; > } > else > { > if(buffer[i]>m) { > sum=-1; > break; > } > temp=t=buffer[i]; > sum+=t; > t=buffer[i]; > > > } > } > sum+=t; > printf("%I64d\n",sum); > getchar(); > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator