結果
| 問題 | No.1251 絶対に間違ってはいけない最小化問題 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-10-24 20:37:18 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 147 ms / 2,000 ms | 
| コード長 | 867 bytes | 
| コンパイル時間 | 1,637 ms | 
| コンパイル使用メモリ | 171,440 KB | 
| 実行使用メモリ | 8,208 KB | 
| 最終ジャッジ日時 | 2024-07-21 15:38:27 | 
| 合計ジャッジ時間 | 14,631 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 42 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
pll ab[200005];
ll cum[200005];
int main(){
    int n;
    cin >> n;
    rep(i,n) cin >> ab[i].first;
    rep(i,n) cin >> ab[i].second;
    sort(ab,ab+n);
    
    cum[0] = 0;
    rep(i,n) cum[i+1] = cum[i] + ab[i].second;
    ll sum = cum[n];
    int l = -1, r = n+1;
    while(r - l > 1){
        int m = (l + r)/2;
        if(sum <= 2*cum[m]) r = m;
        else l = m;
    }
    ll x = ab[r-1].first;
    ll ans = 0;
    rep(i,n){
        ans += ab[i].second * abs(ab[i].first - x);
    }
    cout << x << " " << ans << endl;
    return 0;
}
            
            
            
        