Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- using namespace std;
- ll x=0;
- bool cmp(pair<ll,ll>a, pair<ll,ll>b) {
- ll xx=x;
- if (abs(abs(a.first-a.second)-xx) == abs(abs(b.first-b.second)-xx)) {
- return (a.first+a.second) < (b.first+b.second);
- }
- return (abs(abs(a.first-a.second)-xx) < abs(abs(b.first-b.second)-xx));
- }
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- ll n;
- cin >> n >> x;
- vector<ll>v(n);
- map<ll,ll>m;
- for (auto &i:v) {
- cin >> i;
- m[i]++;
- }
- vector<pair<ll,ll>>a;
- sort(v.begin(), v.end());
- for (int i=0; i<n; i++) {
- ll vl=v[i]-x;
- auto u=lower_bound(v.begin(), v.end(), vl);
- if (u!=v.end() && (*u!=v[i] || m[v[i]]>1)) a.push_back({v[i],*u});
- }
- sort(a.begin(), a.end(), cmp);
- if (!a.empty()) cout << a.front().first << " " << a.front().second;
- else cout << v[0] << " " << v[1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment