fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8. freopen("HOUSE.INP", "r", stdin);
  9. freopen("HOUSE.OUT", "w", stdout);
  10.  
  11. int n;
  12. cin >> n;
  13. vector<pair<ll, ll>> houses(n); // (vị trí, giá tiền)
  14. for (int i = 0; i < n; ++i) {
  15. cin >> houses[i].first >> houses[i].second;
  16. }
  17. sort(houses.begin(), houses.end());
  18.  
  19. ll min_dist = LLONG_MAX;
  20. ll min_cost = LLONG_MAX;
  21. for (int i = 0; i < n - 1; ++i) {
  22. ll d = houses[i + 1].first - houses[i].first;
  23. ll s = houses[i].second + houses[i + 1].second;
  24. if (d < min_dist) {
  25. min_dist = d;
  26. min_cost = s;
  27. } else if (d == min_dist) {
  28. min_cost = min(min_cost, s);
  29. }
  30. }
  31. cout << min_dist << " " << min_cost << '\n';
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty