Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮我看一下

Posted by redbox at 2006-10-02 02:01:32 on Problem 3017
#include <stdio.h>
 int buffer[100000];
int main(void)
{
    long long int n,m,sum,temp,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=0;
            sum+=t;
            t=buffer[i];

    	}
    }
    printf("%I64d",sum);
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator