結果

問題 No.180 美しいWhitespace (2)
ユーザー cormoran
提出日時 2016-09-23 00:18:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,280 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 162,364 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 15:16:27
合計ジャッジ時間 2,682 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define all(v) v.begin(),v.end()

template<class T> bool set_min(T &a, const T &b) { if(a > b) a = b; return a > b; }
template<class T> bool set_max(T &a, const T &b) { if(a < b) a = b; return a < b; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

class Solver {
  public:
    vector<pll> A;    
    ll calc(ll t) {
        ll mx = 0;
        ll mn = 1e18;
        for(pll &a : A) {
            set_max(mx, a.first + a.second * t);
            set_min(mn, a.first + a.second * t);
        }
        return mx - mn;
    }
    
    bool solve() {
        int N; cin >> N;
        A.resize(N);
        for(auto &a : A) cin >> a.first >> a.second;

        ll mx = 0;
        for(auto &a : A) set_max(mx, a.first);
        
        ll l = 1, r = mx;
        while(l + 1 < r) {
            ll a = (l + r) / 2;
            if(calc(a) > calc(a + 1)) l = a;
            else r = a;
        }        
        cout << max(r, 1LL) << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0