HELP FRUIT!
查看原帖
HELP FRUIT!
519092
阿宁已被领养楼主2022/7/26 20:29

这个代码有点难懂为什么会T啊,一定要写快读用STL么?最后一个捆绑数据全T了

#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
long long  n,m,a[300000],b[30000000],c[30000000],ans=0,top1=1,top2=1,tail1=1,tail2=1;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&m);
        a[m]++;
    }
    for(int i=1;i<=100000;i++)
    	while(a[i]!=0)
    	{
			b[tail1]=i;
			a[i]--;
			tail1++;
		}
    while((tail1+tail2-top1-top2)!=1)
    {
        long long t1,t2;
        if((b[top1]<c[top2]&&top1!=tail1)||top2==tail2)
        {
			t1=b[top1];
			top1++;
		}
		else
		{
			t1=c[top2];
			top2++;
		}
        if((b[top1]<c[top2]&&top1!=tail1)||top2==tail2)
		    {
				t2=b[top1];
				top1++;
			}
		else
		{
			t2=c[top2];
			top2++;
		}
		c[tail2]=t1+t2;
		tail2++;
		ans+=t1+t2;
    }
    printf("%lld",ans);
    return 0;
}
2022/7/26 20:29
加载中...