QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619066 | #2442. Welcome Party | PlentyOfPenalty# | AC ✓ | 448ms | 10728kb | C++20 | 1.2kb | 2024-10-07 12:49:12 | 2024-10-07 12:49:13 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define endl '\n'
#define log(...) (void(0))
#endif
using namespace std;
using ll = long long;
using lf = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
const int N = 200011;
const ll INF = 4e18;
pll a[N];
multiset<ll> S;
int main() {
#ifdef memset0
freopen("E.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
int task;
cin >> task;
while (task--) {
S.clear();
S.insert(-INF), S.insert(INF);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second, S.insert(a[i].second);
sort(a + 1, a + n + 1);
ll ans = 4e18, v = -INF;
for (int i = n; i; --i) {
S.erase(S.find(a[i].second));
auto it = S.lower_bound(a[i].first);
if (i < n) ans = min(ans, abs(v - a[i].first));
ll nxt = max(*it, v);
ll pre = max(*--it, v);
ans = min(ans, min(abs(nxt - a[i].first), abs(a[i].first - pre)));
v = max(v, a[i].second);
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 448ms
memory: 10728kb
input:
66 5 27 46 89 13 55 8 71 86 22 35 3 3 5 4 7 6 2 2 0 1000000000 1000000000 0 2 1000000000 0 0 1000000000 2 1000000000 0 1000000000 0 2 0 1000000000 0 1000000000 2 1000000000 1000000000 0 0 2 0 0 0 0 2 1000000000 1000000000 1000000000 1000000000 3 90 30 90 50 90 85 3 0 0 0 2 0 5 3 20 30 20 50 20 70 3 ...
output:
3 1 0 0 1000000000 1000000000 1000000000 0 0 5 0 10 5 10 3 0 10 5 0 5 0 10 5 10 3 0 10 5 0 146595730144168239 10974087366700578 21076180420813408 183538167814754058 46751451188711820 365292306661444331 23639646046527434 40476687889457528 270663364266559542 139940820548070767 21494649603533736 100200...
result:
ok 66 lines