結果
| 問題 | 
                            No.180 美しいWhitespace (2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-09-04 15:45:19 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,334 ms / 5,000 ms | 
| コード長 | 1,426 bytes | 
| コンパイル時間 | 1,121 ms | 
| コンパイル使用メモリ | 83,064 KB | 
| 最終ジャッジ日時 | 2025-01-14 04:29:04 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using lint = long long;
constexpr lint INF = 1LL << 60;
void solve() {
    int n;
    std::cin >> n;
    std::vector<std::pair<lint, lint>> ps(n);
    for (auto& [a, b] : ps) std::cin >> b >> a;
    std::vector<lint> xs{1};
    for (int i = 0; i < n; ++i) {
        auto [a1, b1] = ps[i];
        for (int j = 0; j < n; ++j) {
            auto [a2, b2] = ps[j];
            if (b1 >= b2) continue;
            lint ok = 1, ng = 1 << 30;
            // a1 * ok + b1 < a2 * ok + b2
            while (ng - ok > 1) {
                auto mid = (ok + ng) / 2;
                if (a1 * mid + b1 < a2 * mid + b2) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            xs.push_back(ok);
            xs.push_back(ng);
        }
    }
    std::sort(xs.begin(), xs.end());
    xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
    lint min = INF, xmin = 0;
    for (auto x : xs) {
        lint l = INF, r = -INF;
        for (auto [a, b] : ps) {
            lint y = a * x + b;
            l = std::min(l, y);
            r = std::max(r, y);
        }
        if (r - l < min) {
            min = r - l;
            xmin = x;
        }
    }
    std::cout << xmin << "\n";
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
    return 0;
}