Guest User

Untitled

a guest
Jan 23rd, 2016
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8.  
  9. ll square(int x) {
  10.     return x * (ll) x;
  11. }
  12.  
  13. int main() {
  14.     ios_base::sync_with_stdio(false); cin.tie(0);
  15.  
  16.     int n, x1, y1, x2, y2;
  17.     cin >> n >> x1 >> y1 >> x2 >> y2;
  18.     vector< pair<ll, ll> > dist(n);
  19.     for (int i = 0; i < n; i++) {
  20.         int x, y;
  21.         cin >> x >> y;
  22.         dist[i].first = square(x - x1) + square(y - y1);
  23.         dist[i].second = square(x - x2) + square(y - y2);
  24.     }
  25.  
  26.     sort(dist.begin(), dist.end());
  27.     vector<ll> maxsuf(n + 1);
  28.     for (int i = n - 1; i >= 0; i--) {
  29.         maxsuf[i] = max(maxsuf[i + 1], dist[i].second);
  30.     }
  31.  
  32.     ll result = min(dist[n - 1].first, maxsuf[0]);
  33.     for (int i = 0; i < n; i++) {
  34.         ll r1 = dist[i].first;
  35.         ll r2 = maxsuf[i + 1];
  36.         result = min(result, r1 + r2);
  37.     }
  38.  
  39.     cout << result << '\n';
  40. }
Add Comment
Please, Sign In to add comment