TLE4个点,求如何优化
  • 板块P1631 序列合并
  • 楼主Jorisy
  • 当前回复7
  • 已保存回复7
  • 发布时间2021/11/7 07:36
  • 上次更新2023/11/4 01:12:38
查看原帖
TLE4个点,求如何优化
400269
Jorisy楼主2021/11/7 07:36
#include<bits/stdc++.h>
using namespace std;

priority_queue<int,vector<int>,greater<int>>b;

int read()
{
	int s=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		s=s*10+ch-48;
		ch=getchar();
	}
	return s*f;
}

int main()
{
	int n=read(),a[100005];
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
	}
	for(int i=1;i<=n;i++)
	{
		int m=read();
		for(int j=1;j<=n;j++)
		{
			b.push(m+a[j]);
		}
	}
 	while(n--)
	{
		printf("%d ",b.top());
		b.pop();
	}
	return 0;
}
2021/11/7 07:36
加载中...