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

maxn 不是50;而且你没考虑N=1的情况

Posted by blablabla at 2006-10-25 13:52:34 on Problem 3045
In Reply To:我的怎么会WA?今晚太郁闷了,两道题,WA了15次,没AC一个 Posted by:jiaohang at 2006-10-20 21:25:24
> #include <stdio.h>
> #include<stdlib.h>
> #define maxn 50
> long long w[maxn],s[maxn],num[maxn];
> int N;
> int cmp(const void *a,const void*b)
> {
> 	return w[*(long long*)a]+s[*(long long*)a]-w[*(long long*)b]-s[*(long long*)b];
> }
> int main()
> {
> 	scanf("%d",&N);
> 	for(int i=0;i<N;++i)
> 	{
> 		scanf("%lld%lld",w+i,s+i);
> 		num[i]=i;
> 	}
> 	qsort(num,N,sizeof(long long),cmp);
> 	long long r=0,R,flag=1;
> 	for(int i=1;i<N;++i)
> 	{
> 		r+=w[num[i-1]];
> 
> 		if(r-s[num[i]]>R||flag)
> 		{
> 			R=r-s[num[i]];
> 			flag=0;
> 		}
> 	}
> 	printf("%lld",R);
> 	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