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) {
vector<int> res;
priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
set<pair<int, int>> s;
s.insert({0, 0});
pq.push({A[0]+B[0], {0, 0}});
for (int i=0; i<N; i++)
{
auto t=pq.top();
pq.pop();
res.push_back(t.first);
int a=t.second.first, b=t.second.second;
if (a+1<N&&s.find({a+1, b})==s.end()) s.insert({a+1, b}), pq.push({A[a+1]+B[b], {a+1, b}});
if (b+1<N&&s.find({a, b+1})==s.end()) s.insert({a, b+1}), pq.push({A[a]+B[b+1], {a, b+1}});
}
return res;
}
# | 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... |