#include <bits/stdc++.h>
#include "aplusb.h"
using namespace std;
vector<int> smallest_sums(int n, vector<int> a, vector<int> b) {
priority_queue<pair<int, pair<int, int>>> pq;
vector<int> out(n);
set<pair<int, int>> visited;
int f = 0;
pq.push({a[0] + b[0], {0, 0}});
for (int i = 0; i < n; ++i){
auto h = pq.top();
pq.pop();
out[f] = h.first;
f += 1;
if (!visited.count({h.second.first + 1, h.second.second})){
pq.push({a[h.second.first + 1] + b[h.second.second], {h.second.first + 1, h.second.second}});
visited.insert({h.second.first + 1, h.second.second});
}
if (!visited.count({h.second.first, h.second.second + 1})){
pq.push({a[h.second.first] + b[h.second.second + 1], {h.second.first, h.second.second + 1}});
visited.insert({h.second.first, h.second.second + 1});
}
}
return out;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 2nd token, expected: '3', found: '4' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 2nd token, expected: '3', found: '4' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 2nd token, expected: '3', found: '4' |
6 |
Halted |
0 ms |
0 KB |
- |