| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1358163 | vjudge1 | A Plus B (IOI23_aplusb) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#include "aplusb.h"
struct A{
int i,j,x;
bool operator<(const A&o)const{
return x>o.x;
}
};
priority_queue<A>pq;
set<pair<int,int>>os;
std::vector<int> smallest_sums(int N, std::vector<int> A, std::vector<int> B) {
vector<int>ret;
pq.push({0,0,A[0]+B[0]});
os.insert({0,0});
int n = A.size();
int m = B.size();
while(ret.size() < N){
int i = pq.top().i,j = pq.top().j , v = pq.top().x;
pq.pop();
ret.push_back(v);
if(i+1<n && os.find({i+1,j}) == os.end()){
pq.push({i+1,j,A[i+1]+B[j]});
os.insert({i+1,j});
}
if(j+1<m && os.find({i,j+1}) == os.end()){
pq.push({i,j+1,A[i]+B[j+1]});
os.insert({i,j+1});
}
}
return ret;
}
int main() {
int N;
assert(1 == scanf("%d", &N));
std::vector<int> A(N);
for (int i = 0; i < N; ++i)
assert(1 == scanf("%d", &A[i]));
std::vector<int> B(N);
for (int i = 0; i < N; ++i)
assert(1 == scanf("%d", &B[i]));
fclose(stdin);
std::vector<int> res = smallest_sums(N, A, B);
int n = res.size();
for (int i = 0; i < n; ++i) {
if (i > 0)
printf(" ");
printf("%d", res[i]);
}
printf("\n");
fclose(stdout);
return 0;
}
