Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- struct points
- {
- ll x, y, dist1, dist2;
- };
- bool compare (const points &a, const points &b)
- {
- return a.dist1>b.dist1;
- }
- int main ()
- {
- ll r1=0, r2=0, i, j, k, l, n, x1, y1, x2, y2, ans, maxx=0, minn;
- cin >> n >> x1 >> y1 >> x2 >> y2;
- points a[n];
- for (i=0; i<n; i++)
- {
- scanf("%lld %lld", &a[i].x, &a[i].y);
- a[i].dist1 = (x1-a[i].x)*(x1-a[i].x) + (y1-a[i].y)*(y1-a[i].y);
- a[i].dist2 = (x2-a[i].x)*(x2-a[i].x) + (y2-a[i].y)*(y2-a[i].y);
- }
- if (n==1)
- {
- ll x = (x1-a[0].x)*(x1-a[0].x) + (y1-a[0].y)*(y1-a[0].y);
- ll b = (x2-a[0].x)*(x2-a[0].x) + (y2-a[0].y)*(y2-a[0].y);
- cout << min(x, b);
- return 0;
- }
- sort (a, a+n, compare);
- ans = a[0].dist1;
- r2=a[0].dist2;
- r1=a[1].dist1;
- for (i=1; i<n; i++)
- {
- r1=a[i].dist1;
- if (a[i].dist1!=a[i-1].dist1)
- {
- for (j=1; j<i; j++)
- {
- if (a[j].dist2>r2) r2=a[j].dist2;
- }
- }
- if (r1+r2<ans)
- {
- ans=r1+r2;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement