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。。QAQ#include<iostream> #include<cstdlib> #include<algorithm> using namespace std; const int N=60000+10; struct cow_level{ int weight; int strength; int skill; }cow[N]; int cmp(const void *a,const void *b) { return ((int)(((cow_level *)a)->skill)-(int)(((cow_level *)b)->skill)); } int main() { int T; while(cin>>T){ if(T==1) { cin>>cow[0].weight>>cow[0].strength; cout<<-cow[0].strength<<endl; continue; } int i; for(i=1;i<=T;i++) { cin>>cow[i].weight>>cow[i].strength; cow[i].skill=cow[i].weight+cow[i].strength; } qsort(&cow[1],T,sizeof(cow_level),cmp); int sum=0; i=1; sum+=cow[i].weight; int temp; int maxn=-(1<<29);; while(1) { i++; maxn=max(maxn,(int)sum-(int)cow[i].strength); if(i==T) break; sum+=cow[i].weight; } cout<<maxn<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator