#include <bits/stdc++.h>
#define tii tuple<int, int, int>
using namespace std;
priority_queue<tii, vector<tii>, greater<tii>> pq;
vector<int> ans;
vector<int> smallest_sums(int N, vector<int> A, vector<int> B) {
pq.push({A[0]+B[0], 0, 0});
while(pq.size()) {
int sum = get<0>(pq.top());
int pa = get<1>(pq.top());
int pb = get<2>(pq.top());
pq.pop();
if(ans.size() >= N) continue;
ans.push_back(sum);
if(pa+1 < N) pq.push({A[pa+1]+B[pb], pa+1, pb});
if(pb+1 < N) pq.push({A[pa]+B[pb+1], pa, pb+1});
}
sort(ans.begin(), ans.end());
return ans;
}
# | 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... |