Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct point
- {
- long long x, y;
- point(){}
- point(long long x, long long y) : x(x), y(y) {}
- };
- const long long INF = 2e+18 + 42;
- point a0, b0;
- inline long long dist(point a, point b)
- {
- return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
- }
- struct stcmp
- {
- bool operator() (point a, point b)
- {
- return dist(a, b0) > dist(b, b0);
- }
- };
- inline bool cmpv(point a, point b)
- {
- return dist(a, a0) < dist(b, a0);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- set<point, stcmp> st;
- int n;
- cin >> n;
- cin >> a0.x >> a0.y >> b0.x >> b0.y;
- vector<point> v;
- for (int i = 0; i < n; i++)
- {
- point c;
- cin >> c.x >> c.y;
- v.push_back(c);
- st.insert(c);
- }
- sort(v.begin(), v.end(), cmpv);
- long long ans = dist(*st.begin(), b0);
- for (int i = 0; i < n; i++)
- {
- st.erase(v[i]);
- long long b_dist = 0;
- if (!st.empty())
- {
- b_dist = dist(*st.begin(), b0);
- }
- ans = min(ans, b_dist + dist(v[i], a0));
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement