Submission #16712472


Source Code Expand

#include "bits/stdc++.h"
#include <bits/stdc++.h>

using namespace std;

// #define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    int n;
    cin >> n;
    vector<pair<int,int>> v(n);
    for (auto &it: v) {
        cin >> it.first >> it.second;
    }
    int ans = 0;
    map<int,int> diff, add;
    for (auto [x, y]: v) {
        diff[x - y]++;
        add[x + y]++;
    }
    auto rem = [&] (int v, map<int,int> &mp) {
        int t = --mp[v];
        if (!t) mp.erase(v);
    };
    auto readd = [&] (int v, map<int,int> &mp) {
        mp[v]++;
    };
    for (auto [x, y]: v) {
        rem(x - y, diff);
        rem(x + y, add);

        if (!add.empty()) {
            int now = x + y;
            auto it = add.begin();
            ans = max(ans, now - it->first);
        }
        if (!diff.empty()) {
            int now = -x + y;
            auto it = prev(diff.end());
            ans = max(ans, now + it->first);
        }
        readd(x - y, diff);
        readd(x + y, add);
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Submission Info

Submission Time
Task E - Dist Max
User Not_Afraid
Language C++ (GCC 9.2.1)
Score 500
Code Size 1422 Byte
Status AC
Exec Time 678 ms
Memory 23520 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 18
Set Name Test Cases
Sample sample00, sample01
All handmade02, handmade03, handmade04, handmade05, handmade06, handmade07, handmade08, handmade09, random07, random08, random09, random10, random11, random12, random13, random14, sample00, sample01
Case Name Status Exec Time Memory
handmade02 AC 8 ms 3644 KiB
handmade03 AC 3 ms 3560 KiB
handmade04 AC 2 ms 3560 KiB
handmade05 AC 87 ms 4676 KiB
handmade06 AC 49 ms 4708 KiB
handmade07 AC 266 ms 13680 KiB
handmade08 AC 276 ms 13540 KiB
handmade09 AC 259 ms 13736 KiB
random07 AC 651 ms 23404 KiB
random08 AC 671 ms 23420 KiB
random09 AC 678 ms 23424 KiB
random10 AC 668 ms 23520 KiB
random11 AC 672 ms 23520 KiB
random12 AC 664 ms 23492 KiB
random13 AC 631 ms 22724 KiB
random14 AC 354 ms 16128 KiB
sample00 AC 4 ms 3640 KiB
sample01 AC 2 ms 3644 KiB