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

how can this receive "runtime error"?

Posted by wcm at 2008-08-28 23:27:17 on Problem 3663
#include <stdio.h>

int cmp(const void *p,const void *q)
{
    return *(long *)p > *(long *)q;
}

int main()
{
    int n,i,j,count;
    long s,cow[20000];
    
    scanf("%d%d",&n,&s);

    for(i = 0;i<n;i++)
        scanf("%d",&cow[i]);

    qsort(cow,n,sizeof(long),cmp);

    i = 0;
    j = n-1;
    count = 0;

    while(1)
    {
        while(cow[i]+cow[j] > s)
            j--;

        count += (j-i);

        if (j - i == 1)
            break;

        j = n-1;
        i++;
    }

    printf("%d\n",count);

    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