結果
| 問題 | No.2248 max(C)-min(C) | 
| コンテスト | |
| ユーザー |  kcvlex | 
| 提出日時 | 2023-03-17 22:00:00 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 535 ms / 3,000 ms | 
| コード長 | 1,581 bytes | 
| コンパイル時間 | 3,341 ms | 
| コンパイル使用メモリ | 164,024 KB | 
| 最終ジャッジ日時 | 2025-02-11 13:07:31 | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 51 | 
ソースコード
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <atcoder/all>
#define ALL(V) std::begin(V), std::end(V)
using ll = long long;
const ll INF = 5e15;
ll op(ll a, ll b) {
    return std::max(a, b);
}
ll e() {
    return -INF;
}
int main() {
    using pll = std::pair<ll, ll>;
    ll N;
    std::cin >> N;
    std::vector<ll> A(N), B(N);
    for (auto &e : A) std::cin >> e;
    for (auto &e : B) std::cin >> e;
    std::vector<std::priority_queue<ll, std::vector<ll>, std::greater<ll>>> pq_v(N);
    std::vector<ll> all;
    for (int i = 0; i < N; i++) {
        ll arr[] = { A[i], B[i], (A[i] + B[i]) / 2 };
        for (auto e : arr) {
            all.push_back(e);
            pq_v[i].push(e);
        }
        pq_v[i].push(INF);
    }
    std::priority_queue<pll, std::vector<pll>, std::greater<pll>> pq;
    std::vector<ll> init(N);
    for (int i = 0; i < N; i++) {
        ll v = pq_v[i].top();
        init[i] = v;
        pq.emplace(v, i);
    }
    atcoder::segtree<ll, op, e> seg(init);
    {
        std::sort(ALL(all));
        auto ite = std::unique(ALL(all));
        all.erase(ite, all.end());
    }
    ll ans = INF;
    for (auto e : all) {
        while (true) {
            auto [ v, i ] = pq.top();
            if (e <= v) break;
            pq.pop();
            pq_v[i].pop();
            ll v2 = pq_v[i].top();
            pq.emplace(v2, i);
            seg.set(i, v2);
        }
        auto max = seg.prod(0, N);
        ans = std::min(ans, max - e);
    }
    std::cout << ans << std::endl;
    return 0;
}
            
            
            
        