This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aplusb.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> smallest_sums(int n, std::vector<int> a, std::vector<int> b) {
sort(a.begin(), a.end()); sort(b.begin(), b.end());
vector<int> ans;
set< pair<int, int> > st = {};
priority_queue< tuple<int, int, int>, vector< tuple<int, int, int> >, greater<> > pq; pq.push({a[0] + b[0], 0, 0});
while ((int) ans.size() < n) {
int x = get<0>(pq.top()), i = get<1>(pq.top()), j = get<2>(pq.top());
pq.pop();
if (st.count({i, j})) continue;
st.insert({i, j});
ans.push_back(x);
if (i < n - 1) pq.push({a[i + 1] + b[j], i + 1, j});
if (j < n - 1) pq.push({a[i] + b[j + 1], i, j + 1});
}
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... |