Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<fstream>
- #include<vector>
- #include<algorithm>
- #include<queue>
- #include<array>
- #define long long long
- #define nln '\n'
- #define pairl pair<long, long>
- const long N = 5*1e4, I = 1e9;
- using namespace std;
- // Global variables: f1, f2, n, m, k, a, b, c
- fstream f1, f2;
- inline void openf()
- {
- f1.open("kmin.inp", ios:: in);
- f2.open("kmin.out", ios:: out);
- }
- inline void closef()
- {
- f1.close();
- f2.close();
- }
- long m, n, k;
- vector<long> a, b, c;
- void data()
- {
- f1.tie(0)->sync_with_stdio(0);
- f2.tie(0)->sync_with_stdio(0);
- //cin.tie(0)->sync_with_stdio(0);
- cin >> m >> n >> k;
- a.push_back(I);
- for (long i = 0; i != m; ++i)
- {
- long x;
- cin >> x;
- a.push_back(x);
- }
- b.push_back(I);
- for (long i = 0; i != n; ++i)
- {
- long x;
- cin >> x;
- b.push_back(x);
- }
- }
- void process()
- {
- sort(a.begin()+1, a.end());
- sort(b.begin()+1, b.end());
- priority_queue<array<long, 3>, vector<array<long, 3>>, greater<array<long, 3>>> pqu; // less
- for (long i = 1; i-1 != n; ++i)
- pqu.push({a[1] + b[i], 1, i});
- while (!pqu.empty() && k > 0)
- {
- --k;
- auto tak = pqu.top();
- pqu.pop();
- cout << tak[0] << nln;
- if (tak[1]+1 <= m)
- pqu.push({a[tak[1]+1]+b[tak[2]], tak[1]+1, tak[2]});
- }
- cout << nln;
- }
- void view()
- {
- for (const auto &i: c)
- cout << i << ' ' << nln;
- }
- int main()
- {
- openf();
- data();
- process();
- view();
- closef();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment