Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的代码为什么总是超时那位大哥大姐帮我看看

Posted by woainiyanyan at 2009-08-28 09:32:44 on Problem 3646
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator