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[10000]; int b[10000]; int i,j,k; int n,m; int num=0; while(cin>>n>>m) { for(i=0;i<n;i++) { cin>>a[i]; num+=a[i]; } for(j=0;j<m;j++) cin>>b[j]; for( k=0;k<n;k++) { for(j=k;j<n-1;j++) { if(a[j+1]<a[k]) { int t; t=a[j+1]; a[j+1]=a[k]; a[k]=t; } } } for( k=0;k<m;k++) { for( j=k;j<m-1;j++) { if(b[j+1]<b[k]) { int t; t=b[j+1]; b[j+1]=b[k]; b[k]=t; } } } int sum=0;int t; for(j=0;j<n;j++) { t=j; while(1) { if(b[t]>=a[j]) { sum+=b[t]; break; } else t++; if(k>=m) break; } } if(n>m||sum<num) cout<<"Loowater is doomed!"<<endl; else cout<<sum<<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