結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
![]() |
提出日時 | 2023-03-17 22:22:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 164 ms / 3,000 ms |
コード長 | 1,237 bytes |
コンパイル時間 | 1,764 ms |
コンパイル使用メモリ | 204,820 KB |
最終ジャッジ日時 | 2025-02-11 13:31:19 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#include <bits/stdc++.h>using ll = long long;using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(0);int n;cin >> n;vector<array<int, 3>> a(n);vector<int> b(n * 3);for (int i = 0; i < n; i++) {cin >> a[i][0];}for (int i = 0; i < n; i++) {cin >> a[i][2];if (a[i][0] > a[i][2]) swap(a[i][0], a[i][2]);a[i][1] = (a[i][0] + a[i][2]) / 2;for (int h = 0; h < 3; h++) {b[i * 3 + h] = a[i][h];}}sort(b.begin(), b.end());vector<int> c(n, 0);priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;int a1 = 0;for (int i = 0; i < n; i++) {a1 = max(a1, a[i][0]);pq.push({ a[i][0], i });}int r = a1 - b[0];//cout << a1 << ' ' << b[0] << endl;for (const auto &a0 : b) {while (pq.top().first < a0) {auto [_, i] = pq.top(); pq.pop();if (c[i] == 2) {cout << r << endl;exit(0);}int t = a[i][++c[i]];a1 = max(a1, t);pq.push({ t, i });}r = min(r, a1 - a0);}cout << r << endl;return 0;}