| ||||||||||
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 |
为什么这样还超时???#include<iostream> using namespace std; int main() { int a[10001]; int t; while(scanf("%d",&t)==1) { int i,j; int n,s,num; int sum,len,max; while(t) { max=0; len=sum=0; memset(a,0,10001*sizeof(int)); scanf("%d%d",&n,&s); for(i=0;i<n;i++) { scanf("%d",&num); a[num]++; if(num>=s)len=1; if(num>0)sum+=num; if(num>max)max=num; } if(len==1) { printf("1\n"); continue; } if(sum<s) { printf("0\n"); continue; } sum=0; len=0; i=max; while(sum<s) { for(j=0;j<a[i];j++) { if(sum>=s)break; sum+=(i-); len++; } i--; } printf("%d\n",len); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator