tuki2501

kmin.cpp

Nov 7th, 2021
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 50005;
  5.  
  6. int n, m, k;
  7. int a[N], b[N];
  8.  
  9. int main() {
  10.   cin >> n >> m >> k;
  11.   for (int i = 1; i <= n; i++) {
  12.     cin >> a[i];
  13.   }
  14.   for (int i = 1; i <= m; i++) {
  15.     cin >> b[i];
  16.   }
  17.   sort(a + 1, a + n + 1);
  18.   sort(b + 1, b + m + 1);
  19.   priority_queue<array<int,3>, vector<array<int,3>>, greater<array<int,3>>> q;
  20.   for (int i = 1; i <= m; i++) {
  21.     q.push({a[1] + b[i], 1, i});
  22.   }
  23.   while (q.size() && k) {
  24.     auto i = q.top(); q.pop();
  25.     k--;
  26.     cout << i[0] << '\n';
  27.     if (i[1] + 1 <= n) q.push({a[i[1] + 1] + b[i[2]], i[1] + 1, i[2]});
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment