#include "aplusb.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> smallest_sums(int n, vector<int> A, vector<int> B) {
set<int >s;
priority_queue<tuple<int,int,int> , vector<tuple<int,int,int> > , greater<tuple<int,int,int> > > pq;
pq.push({A[0] + B[0], 0, 0});
set<pair<int,int> > st;
vector<int> ans;
for(int i = 0;i<n;i++){
int val = get<0>(pq.top());
int posa = get<1>(pq.top());
int posb = get<1>(pq.top());
pq.pop();
ans.push_back(val);
if(posa + 1 < n && !st.count({posa + 1, posb})){
pq.push({A[posa + 1] + B[posb],posa+1, posb});
st.insert({posa+1, posb});
}
if(posb + 1 < n && !st.count({posa, posb+1})){
pq.push({A[posa] + B[posb+1],posa, posb+1});
st.insert({posa, posb+1});
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 3rd token, expected: '2', found: '30' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 3rd token, expected: '2', found: '30' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 3rd token, expected: '2', found: '30' |
8 |
Halted |
0 ms |
0 KB |
- |