# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
947807 | biank | A Plus B (IOI23_aplusb) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#include "aplusb.h"
using namespace std;
#define sz(x) int(x.size())
using ii = pair<int, int>;
using vi = vector<int>;
vi smallest_sums(int N, vi A, vi B) {
priority_queue<pair<int, ii>, vector<pair<int, ii>>, greater<pair<int, ii>>> pq;
set<ii> visited;
auto push = [&](int i, int j) {
pq.emplace(a[i] + b[j], {i, j});
vis.emplace(i, j);
};
push(0, 0);
vi ans;
while (sz(ans) < N) {
auto [sum, pos] = pq.top();
ans.push_back(sum);
pq.pop();
auto [i, j] = pos;
if (i + 1 < N && !vis.count({i + 1, j})) {
push(i + 1, j);
}
if (j + 1 < N && !vis.count({i, j + 1})) {
push(i, j + 1);
}
}
return {};
}