Salvens

D

Aug 7th, 2023
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. #define int long long
  7.  
  8. const long long INF = 1e9 + 7;
  9. const int MAXN = 200 + 10;
  10. const int N = 1e5 + 10;
  11.  
  12. void read(int& n, vector<int>& a) {
  13.     cin >> n;
  14.     a.resize(n);
  15.     for (int i = 0; i < n; ++i) {
  16.         cin >> a[i];
  17.     }
  18.     sort(a.begin(), a.end());
  19. }
  20.  
  21. int top1 = 0, top2 = 0, top3 = 0, top4 = 0;
  22. int n1, n2, n3, n4;
  23. vector<int> a1, a2, a3, a4;
  24. int ans1, ans2, ans3, ans4;
  25.  
  26. void print_ans() {
  27. //    cout << "ANSWER: ";
  28.     cout << ans1 << ' ' << ans2 << ' ' << ans3 << ' ' << ans4 << '\n';
  29.     exit(0);
  30. }
  31.  
  32. void iterate() {
  33.     vector<pair<int, int>> mn;
  34.     if (top1 != n1 - 1) {
  35.         mn.emplace_back(a1[top1], 1);
  36.     }
  37.     if (top2 != n2 - 1) {
  38.         mn.emplace_back(a2[top2], 2);
  39.     }
  40.     if (top3 != n3 - 1) {
  41.         mn.emplace_back(a3[top3], 3);
  42.     }
  43.     if (top4 != n4 - 1) {
  44.         mn.emplace_back(a4[top4], 4);
  45.     }
  46.     sort(mn.begin(), mn.end());
  47.     if (mn.empty()) {
  48.         print_ans();
  49.     }
  50.     int pos = mn[0].second;
  51.     if (pos == 1) {
  52.         ++top1;
  53.     }
  54.     if (pos == 2) {
  55.         ++top2;
  56.     }
  57.     if (pos == 3) {
  58.         ++top3;
  59.     }
  60.     if (pos == 4) {
  61.         ++top4;
  62.     }
  63. }
  64.  
  65. signed main() {
  66.     ios_base::sync_with_stdio(false);
  67.     cin.tie(nullptr);
  68.     cout.tie(nullptr);
  69.  
  70.     read(n1, a1);
  71.     read(n2, a2);
  72.     read(n3, a3);
  73.     read(n4, a4);
  74.  
  75.     int dif = INF;
  76.     while (true) {
  77.         int maxi = max({a1[top1], a2[top2], a3[top3], a4[top4]});
  78.         int mini = min({a1[top1], a2[top2], a3[top3], a4[top4]});
  79.         if (maxi - mini < dif) {
  80.             dif = maxi - mini;
  81.             ans1 = a1[top1];
  82.             ans2 = a2[top2];
  83.             ans3 = a3[top3];
  84.             ans4 = a4[top4];
  85.         }
  86.  
  87.         iterate();
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment