#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define N 24
#define maxn 2000005
vector<int> smallest_sums(int n,vector<int> a,vector<int> b){
vector<int> ans;
int i=0,j=0,k=0;
priority_queue<pair<int,pair<int,int> >,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > pq;
pq.push({a[0]+b[0],{0,0}});
map<int,map<int,bool> > vis;
while(k<n){
pair<int,pair<int,int> > pp=pq.top();
pq.pop();
if(vis[pp.ss.ff][pp.ss.ss]) continue;
vis[pp.ss.ff][pp.ss.ss]=true;
ans.pb(pp.first);
k++;
if(pp.ss.ff+1<n){
pq.push({a[pp.ss.ff+1]+b[pp.ss.ss],{pp.ss.ff+1,pp.ss.ss}});
}
if(pp.ss.ss+1<n){
pq.push({a[pp.ss.ff]+b[pp.ss.ss+1],{pp.ss.ff,pp.ss.ss+1}});
}
}
return ans;
}
//
// void solve(){
// int n;
// vector<int> a,b;
// cin>>n;
// for(int i=1; i<=n; i++){
// int x;
// cin>>x;
// a.pb(x);
// }
// for(int i=1; i<=n; i++){
// int x;
// cin>>x;
// b.pb(x);
// }
// vector<int> ans=smallest_sums(n,a,b);
// for(int i=0; i<ans.size(); i++) cout<<ans[i]<<' ';
// }
//
// int main(){
// // freopen("in.txt","w",stdout);
// // freopen("out.txt","r",stdin);
// ios_base::sync_with_stdio(0); cin.tie(0);
// int t=1;
// // cin>>t;
// while(t--) solve();
// }
//
// 4
// 2 2 2 2
// 2 3 3 3
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |