| ||||||||||
| 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 | |||||||||
我的怎么会WA?今晚太郁闷了,两道题,WA了15次,没AC一个#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator