結果
| 問題 | 
                            No.180 美しいWhitespace (2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tottoripaper
                         | 
                    
| 提出日時 | 2015-07-29 22:05:38 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1 ms / 5,000 ms | 
| コード長 | 760 bytes | 
| コンパイル時間 | 176 ms | 
| コンパイル使用メモリ | 35,968 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-17 22:22:28 | 
| 合計ジャッジ時間 | 1,088 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%d %d", A+i, B+i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <cstdio>
#include <limits>
#include <algorithm>
typedef long long ll;
const ll MAX = std::numeric_limits<ll>::max();
int N;
int A[1000], B[1000];
ll lb = 1, ub = 1001001001;
ll f(ll x){
    ll mn = MAX, mx = -MAX;
    
    for(int i=0;i<N;i++){
        ll y = x * B[i] + A[i];
        mn = std::min(mn, y);
        mx = std::max(mx, y);
    }
    return mx - mn;
}
int main(){
    scanf("%d", &N);
    for(int i=0;i<N;i++){
        scanf("%d %d", A+i, B+i);
    }
    while(ub - lb > 2){
        ll a = (1ll * ub + 2ll * lb) / 3, b = (2ll * ub + 1ll * lb) / 3;
        if(f(a) <= f(b)){ub = b;}
        else{lb = a;}
    }
    ll res = lb;
    for(ll i=lb+1;i<ub;i++){
        if(f(res) > f(i)){res = i;}
    }
    printf("%lld\n", res);
}
            
            
            
        
            
tottoripaper