# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1130618 | lopkus | A Plus B (IOI23_aplusb) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define int long long
//#include "aplusb.h"
using namespace std;
std::vector<int> smallest_sums(int N, std::vector<int> A, std::vector<int> B) {
set<pair<int, pair<int,int> > >s;
s.insert({A[0] + B[0], {0, 0}});
vector<int> ans;
while(ans.size() != N) {
int u = (*s.begin()).first;
int i = (*s.begin()).second.first;
int j = (*s.begin()).second.second;
auto it = s.begin();
s.erase(it);
ans.push_back(u);
if(i + 1 < N) {
s.insert({A[i + 1] + B[j], {i + 1 , j}});
}
if(j + 1 < N) {
s.insert({A[i] + B[j + 1], {i, j + 1}});
}
}
return ans;
}
/*
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
for(auto it : smallest_sums(3, {0, 2, 2}, {3, 5, 6})) {
cout << it << " ";
}
}*/