# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1190282 | zawka | A Plus B (IOI23_aplusb) | C++20 | 0 ms | 0 KiB |
#include "bits/stdc++.h"
using namespace std;
vector<int> smallest_sum(int n, vector<int> a, vector<int> b)
{
priority_queue<pair<int,pair<int,int>>> kolejka;
set<pair<int,int>> secik;
vector<int> wynik(n);
kolejka.push({-(a[0]+b[0]),{0,0}});
for(int i=0; i<n; i++)
{
wynik[i]=-kolejka.top().first;
int y=kolejka.top().second.first;
int x=kolejka.top().second.second;
kolejka.pop();
if(y+1<n && secik.find({y+1,x})==secik.end())
{
kolejka.push({-(a[y+1]+b[x]),{y+1,x}});
secik.insert({y+1,x});
}
if(x+1<n && secik.find({y,x+1})==secik.end())
{
kolejka.push({-(a[y]+b[x+1]),{y,x+1}});
secik.insert({y,x+1});
}
}
return wynik;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<int> c(n),d(n);
for(int i=0; i<n; i++)
{
cin>>c[i];
}
for(int i=0; i<n; i++)
{
cin>>d[i];
}
vector<int> ans=smallest_sum(n,c,d);
for(int i=0; i<n; i++)
{
cout<<ans[i]<<' ';
}
return 0;
}