RE+WA求助
查看原帖
RE+WA求助
571348
PartiallyCorrect楼主2024/10/23 19:48
#include<bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define PII pair<int,int>
using namespace std;
queue<int> q, q1;
const int N = 1e5 + 5;
int t[N];
inline int get()
{
	if(q.empty() or q1.front() < q.front())
	{
		int x = q1.front();
		q1.pop();
		return x;
	}
	if(q1.empty() or q.front() < q1.front())
	{
		int x = q.front();
		q.pop();
		return x;
	}
}
int read()
{
	int x = 0, flag = 0;
	char a = getchar();
	while(a > '9' or a < '0')
    {
		if(a == '-')flag = 1;
		a = getchar();
	}
	while(a >= '0' and a <= '9')
    {
		x = x * 10 + a - '0';
		a = getchar();
	}
	return flag ? -x : x;
}
void write(int x)
{
	if(x < 0)
    {
		putchar('-');
		x = -x;
	}
	if(x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}
signed main()
{
	int n = read();
	for(int i = 1 ; i <= n ; i ++)t[read()] ++;
	for(int i = 1 ; i <= 1e5 ; i ++)
		while(t[i] --)q.push(i);
	int ans = 0;
	for(int i = 1 ; i < n ; i ++)
	{
		int x = get();
		int y = get();
		ans += x + y;
		q1.push(x + y);
	}
	write(ans);
	return 0;
}
2024/10/23 19:48
加载中...