Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using Vector = pair<int, int>;
- #define x first
- #define y second
- int cross(Vector x, Vector y) {
- return x.x * y.y - x.y * y.x;
- }
- int getQuater(Vector vec) {
- auto [x, y] = vec;
- if (x >= 0 && y >= 0) return 0;
- if (x < 0 && y >= 0) return 1;
- if (x < 0 && y < 0) return 2;
- if (x >= 0 && y < 0) return 3;
- return -1;
- }
- bool comp(Vector vec1, Vector vec2) {
- int quater1 = getQuater(vec1);
- int quater2 = getQuater(vec2);
- if (quater1 != quater2) return quater1 < quater2;
- return cross(vec1, vec2) > 0;
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n;
- cin >> n;
- vector<Vector> vecs(n);
- for (auto &vec : vecs) cin >> vec.x >> vec.y;
- sort(vecs.begin(), vecs.end(), comp);
- long long best = 0;
- int sumX = 0, sumY = 0;
- int p = n - 1, cnt = 0;
- auto update = [&]() {
- best = max(best, 1LL * sumX * sumX + 1LL * sumY * sumY);
- };
- for (int i = 0; i < n; i++) {
- while (cnt < n && cross(vecs[i], vecs[(p + 1) % n]) >= 0) {
- p = (p + 1) % n;
- sumX += vecs[p].x, sumY += vecs[p].y;
- cnt++;
- update();
- }
- cnt--;
- sumX -= vecs[i].x, sumY -= vecs[i].y;
- update();
- }
- cout << best << '\n';
- return 0;
- }
Advertisement
RAW Paste Data
Copied
Advertisement