Subject to the effect:
Topic links: https://www.luogu.org/problemnew/show/P1631
There are two lengths
sequences
and
, in
and
the sum can be obtained from each of a number
Ge and, asked this
th smallest and
a.
Digression:
I accuracy rate is really low qwq
Ideas:
As the title says
are monotonically increasing. So we can not consider the sort.
Monotonically increasing at the same time meet the special
So every time we just maintenance
minimum value can be a number (respectively
, Which
Show
've accomplished maintained
Array Pointer)
for the minimum may be considered to maintain a small heap root. Each element maintain a triple
, indicates that this
value.
in case
Is the minimum heap, then the output
Pop-up, and insert
.
do
times the above-described method may be.
time complexity
Code:
#include <queue>
#include <cstdio>
#define mp make_pair
using namespace std;
const int N=100010;
int n,a[N],b[N];
priority_queue<pair<int,pair<int,int> > > q; //pair套pair最为致命(三元组)
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
for (int i=1;i<=n;i++)
scanf("%d",&b[i]);
for (int i=1;i<=n;i++)
q.push(mp(-a[i]-b[1],mp(i,1))); //插入初始值
for (int i=1;i<=n;i++)
{
printf("%d ",-q.top().first);
int x=q.top().second.first,y=q.top().second.second;
q.pop();
q.push(mp(-a[x]-b[y+1],mp(x,y+1)));
}
return 0;
}