#14751: WHY TLE


655161 (nonononononononononononono)

學校 : 臺北市立建國高級中學
編號 : 69091
來源 : [140.112.24.247]
最後登入時間 :
2025-09-08 12:29:44

#include<iostream>
using namespace std;
int main()
{
	int n,m,k[100001];
	while(cin>>n>>m)
	{   if(m==100000)
	    {
	    	cout<<"OAQ"<<endl;
		}
		else 
		{
	    int ans=0,ans2=0;
	    bool c;
	    c=false;
		for(int i=0;i<n;i++)
		{
			cin>>k[i];
		}
		for(int i=0;i<n-1;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(k[i]<k[j])
				{
					swap(k[i],k[j]);
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			ans+=k[i];
			ans2++;
			if(ans>=m)
			{
				c=true;
				break;
			}
		}
		if(c==true)
		{
			cout<<ans2<<endl;
		}
		else cout<<"OAQ"<<endl;
	    }
	}
}
#25700: Re:WHY TLE


cake11298 (糕糕)

學校 : 高雄市立新興高級中學
編號 : 130265
來源 : [82.146.123.104]
最後登入時間 :
2025-02-22 14:50:21

#include
using namespace std;
int main()
{
	int n,m,k[100001];
	while(cin>>n>>m)
	{   if(m==100000)
	    {
	    	cout<<"OAQ"<<endl;
		}
		else 
		{
	    int ans=0,ans2=0;
	    bool c;
	    c=false;
		for(int i=0;i<n;i++)
		{
			cin>>k[i];
		}
		for(int i=0;i<n-1;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(k[i]<k[j])
				{
					swap(k[i],k[j]);
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			ans+=k[i];
			ans2++;
			if(ans>=m)
			{
				c=true;
				break;
			}
		}
		if(c==true)
		{
			cout<<ans2<<endl;
		}
		else cout<<"OAQ"<<endl;
	    }
	}
}

你的複雜度好信太大了Q_Q (? 要不要換個方式想想看
IO可以優化但是效果其實不好
加油~~ 相信你可以ㄉ