Iamtui1010

kmin

Nov 9th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<fstream>
  4. #include<vector>
  5. #include<algorithm>
  6. #include<queue>
  7. #include<array>
  8.  
  9. #define long long long
  10. #define nln '\n'
  11. #define pairl pair<long, long>
  12.  
  13. const long N = 5*1e4, I = 1e9;
  14.  
  15. using namespace std;
  16.  
  17. // Global variables: f1, f2, n, m, k, a, b, c
  18.  
  19. fstream f1, f2;
  20.  
  21. inline void openf()
  22. {
  23.     f1.open("kmin.inp", ios:: in);
  24.     f2.open("kmin.out", ios:: out);
  25. }
  26.  
  27. inline void closef()
  28. {
  29.     f1.close();
  30.     f2.close();
  31. }
  32.  
  33. long m, n, k;
  34. vector<long> a, b, c;
  35.  
  36. void data()
  37. {
  38.     f1.tie(0)->sync_with_stdio(0);
  39.     f2.tie(0)->sync_with_stdio(0);
  40.     //cin.tie(0)->sync_with_stdio(0);
  41.     cin >> m >> n >> k;
  42.  
  43.     a.push_back(I);
  44.     for (long i = 0; i != m; ++i)
  45.     {
  46.         long x;
  47.         cin >> x;
  48.         a.push_back(x);
  49.     }
  50.  
  51.     b.push_back(I);
  52.     for (long i = 0; i != n; ++i)
  53.     {
  54.         long x;
  55.         cin >> x;
  56.         b.push_back(x);
  57.     }
  58. }
  59.  
  60. void process()
  61. {
  62.     sort(a.begin()+1, a.end());
  63.     sort(b.begin()+1, b.end());
  64.  
  65.     priority_queue<array<long, 3>, vector<array<long, 3>>, greater<array<long, 3>>> pqu; // less
  66.  
  67.     for (long i = 1; i-1 != n; ++i)
  68.         pqu.push({a[1] + b[i], 1, i});
  69.  
  70.     while (!pqu.empty() && k > 0)
  71.     {
  72.         --k;
  73.         auto tak = pqu.top();
  74.         pqu.pop();
  75.         cout << tak[0] << nln;
  76.         if (tak[1]+1 <= m)
  77.             pqu.push({a[tak[1]+1]+b[tak[2]], tak[1]+1, tak[2]});
  78.     }
  79.     cout << nln;
  80. }
  81.  
  82. void view()
  83. {
  84.     for (const auto &i: c)
  85.         cout << i << ' ' << nln;
  86. }
  87.  
  88. int main()
  89. {
  90.     openf();
  91.     data();
  92.     process();
  93.     view();
  94.     closef();
  95.     return 0;
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment