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 |
第一次超时 优化后64MS。。。#include<cstdio> #include<algorithm> using namespace std; int main() { int n,s; int i,j; int cow[20005]; int n_sum; scanf("%d%d",&n,&s); for(i=0; i<n; i++) scanf("%d",&cow[i]); sort(cow,cow+n); j=0; n_sum=0; int k=0; for(i=n-1; i>=0; i--) { if(i>j) { n_sum+=k; for(; j<i; j++) { if(cow[i]+cow[j]<=s) { k++; n_sum++; } else break; } } else { n_sum+=i*(i+1)/2; break; } } printf("%d\n",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