Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const long long INF = 1e9 + 7;
- const int MAXN = 200 + 10;
- const int N = 1e5 + 10;
- void read(int& n, vector<int>& a) {
- cin >> n;
- a.resize(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- sort(a.begin(), a.end());
- }
- int top1 = 0, top2 = 0, top3 = 0, top4 = 0;
- int n1, n2, n3, n4;
- vector<int> a1, a2, a3, a4;
- int ans1, ans2, ans3, ans4;
- void print_ans() {
- // cout << "ANSWER: ";
- cout << ans1 << ' ' << ans2 << ' ' << ans3 << ' ' << ans4 << '\n';
- exit(0);
- }
- void iterate() {
- vector<pair<int, int>> mn;
- if (top1 != n1 - 1) {
- mn.emplace_back(a1[top1], 1);
- }
- if (top2 != n2 - 1) {
- mn.emplace_back(a2[top2], 2);
- }
- if (top3 != n3 - 1) {
- mn.emplace_back(a3[top3], 3);
- }
- if (top4 != n4 - 1) {
- mn.emplace_back(a4[top4], 4);
- }
- sort(mn.begin(), mn.end());
- if (mn.empty()) {
- print_ans();
- }
- int pos = mn[0].second;
- if (pos == 1) {
- ++top1;
- }
- if (pos == 2) {
- ++top2;
- }
- if (pos == 3) {
- ++top3;
- }
- if (pos == 4) {
- ++top4;
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- read(n1, a1);
- read(n2, a2);
- read(n3, a3);
- read(n4, a4);
- int dif = INF;
- while (true) {
- int maxi = max({a1[top1], a2[top2], a3[top3], a4[top4]});
- int mini = min({a1[top1], a2[top2], a3[top3], a4[top4]});
- if (maxi - mini < dif) {
- dif = maxi - mini;
- ans1 = a1[top1];
- ans2 = a2[top2];
- ans3 = a3[top3];
- ans4 = a4[top4];
- }
- iterate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment