求助,只有#1#2AC,#3WA,其余全部TLE
查看原帖
求助,只有#1#2AC,#3WA,其余全部TLE
663638
Butterfly_qwq楼主2022/4/30 14:13
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int p;
ll read()
{
    ll x=0,f=1;
	char ch=getchar();
    while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
    return x*f;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
ll arr[(int)1e7+1],csrt[(int)1e5+1];
void csort(ll n)
{
	p=0;
	memset(csrt,0,sizeof(csrt));
	for(ll i=0;i<n;i++)
		if(arr[i]!=0)csrt[arr[i]]++;
	memset(arr,0,sizeof(arr));
	for(ll i=0;i<=1e5;i++)
	{
		for(ll j=0;j<csrt[i];j++)
		{
			arr[p]=i;
			p++;
		}
	}
}
int main()
{
	ll n,ans=0;
	n=read();
	for(ll i=0;i<n;i++)arr[i]=read();
	while(1)
	{
		csort(n);
		if(arr[1]==0)break;
		ans+=(arr[0]+arr[1]);
		arr[1]+=arr[0];
		arr[0]=0;
	}
	cout<<ans;
	return 0;
}
2022/4/30 14:13
加载中...