lina_os

Untitled

May 1st, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define ld long double
  5.  
  6. using namespace std;
  7. ll x=0;
  8. bool cmp(pair<ll,ll>a, pair<ll,ll>b) {
  9. ll xx=x;
  10. if (abs(abs(a.first-a.second)-xx) == abs(abs(b.first-b.second)-xx)) {
  11. return (a.first+a.second) < (b.first+b.second);
  12. }
  13. return (abs(abs(a.first-a.second)-xx) < abs(abs(b.first-b.second)-xx));
  14. }
  15.  
  16. int main() {
  17. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  18. ll n;
  19. cin >> n >> x;
  20. vector<ll>v(n);
  21. map<ll,ll>m;
  22. for (auto &i:v) {
  23. cin >> i;
  24. m[i]++;
  25. }
  26. vector<pair<ll,ll>>a;
  27. sort(v.begin(), v.end());
  28. for (int i=0; i<n; i++) {
  29. ll vl=v[i]-x;
  30. auto u=lower_bound(v.begin(), v.end(), vl);
  31. if (u!=v.end() && (*u!=v[i] || m[v[i]]>1)) a.push_back({v[i],*u});
  32. }
  33. sort(a.begin(), a.end(), cmp);
  34. if (!a.empty()) cout << a.front().first << " " << a.front().second;
  35. else cout << v[0] << " " << v[1];
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment