| ||||||||||
| 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 | |||||||||
why is it wrong?#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(long*)a-*(long*)b;
}
int main()
{
int i,L,m,n,p;
long sum,p1=0,p2=0;
long a[20001],d[10001];
scanf("%d%d",&n,&L);
for(i=0;i<n;i++)
{
scanf("%ld%ld",&a[2*i],&a[2*i+1]);
}
qsort(a,2*n,sizeof(long),cmp);
for(i=0;i<n;i++)
{
d[i]=a[2*i+1]-a[2*i];
if(d[i]%L==0)
{ p1+=d[i]/L; }
else
{
m=(d[i]/L+1)*L-d[i];
p=a[2*i+1]+m;
if(p>a[2*i+2])
{
a[2*i+2]=p;
}
p2+=d[i]/L+1;
}
}
sum=p1+p2;
printf("%ld\n",sum);
return(0);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator