Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int INF = (int)1e9;
- vector<pair<int, int>> a, b, c;
- vector<int> ans(3);
- int n, m, k, mn = INF, mx = 0;
- int f(int a, int b, int c)
- {
- return abs(a - b) + abs(a - c) + abs(b - c);
- }
- void check(int i1, int i2, int i3)
- {
- int cur = f(a[i1].first, b[i2].first, c[i3].first);
- if(cur < mn)
- {
- ans = {a[i1].second, b[i2].second, c[i3].second};
- mn = cur;
- mx = a[i1].first + b[i2].first + c[i3].first;
- }
- else if(cur == mn && a[i1].first + b[i2].first + c[i3].first > mx)
- {
- ans = {a[i1].second, b[i2].second, c[i3].second};
- mx = a[i1].first + b[i2].first + c[i3].first;
- }
- }
- main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cin >> n >> m >> k;
- a.resize(n);
- b.resize(m);
- c.resize(k);
- for(int i = 0; i < n; i++)
- {
- cin >> a[i].first;
- a[i].second = i;
- }
- for(int i = 0; i < m; i++)
- {
- cin >> b[i].first;
- b[i].second = i;
- }
- for(int i = 0; i < k; i++)
- {
- cin >> c[i].first;
- c[i].second = i;
- }
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- sort(c.begin(), c.end());
- int i1 = 0, i2 = 0, i3 = 0;
- while(true)
- {
- if(i1 == n - 1 && i2 == m - 1 && i3 == k - 1)
- break;
- check(i1, i2, i3);
- if(i1 != n - 1)
- check(i1 + 1, i2, i3);
- if(i2 != m - 1)
- check(i1, i2 + 1, i3);
- if(i3 != k - 1)
- check(i1, i2, i3 + 1);
- if(i1 == n - 1 && i2 == m - 1)
- ++i3;
- else if(i1 == n - 1 && i3 == k - 1)
- ++i2;
- else if(i2 == m - 1 && i3 == k - 1)
- ++i1;
- else if(i1 == n - 1)
- {
- if(b[i2].first < c[i3].first)
- ++i2;
- else
- ++i3;
- }
- else if(i2 == m - 1)
- {
- if(a[i1].first < c[i3].first)
- ++i1;
- else
- ++i3;
- }
- else if(i3 == k - 1)
- {
- if(a[i1].first < b[i2].first)
- ++i1;
- else
- ++i2;
- }
- else
- {
- int minim = min({a[i1].first, b[i2].first, c[i3].first});
- if(a[i1].first == minim)
- ++i1;
- else if(b[i2].first == minim)
- ++i2;
- else
- ++i3;
- }
- }
- for(auto i : ans)
- cout << i + 1 << " ";
- }
Add Comment
Please, Sign In to add comment