結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー kappybarkappybar
提出日時 2020-10-24 20:37:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 170,128 KB
実行使用メモリ 8,304 KB
最終ジャッジ日時 2023-09-28 20:49:55
合計ジャッジ時間 18,284 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,500 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 133 ms
7,828 KB
testcase_19 AC 129 ms
7,820 KB
testcase_20 AC 75 ms
6,636 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 81 ms
6,768 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 105 ms
6,980 KB
testcase_25 AC 77 ms
6,720 KB
testcase_26 AC 30 ms
6,320 KB
testcase_27 AC 9 ms
4,380 KB
testcase_28 AC 139 ms
7,972 KB
testcase_29 AC 139 ms
8,120 KB
testcase_30 AC 140 ms
8,032 KB
testcase_31 AC 140 ms
8,028 KB
testcase_32 AC 139 ms
8,076 KB
testcase_33 AC 139 ms
8,036 KB
testcase_34 AC 139 ms
7,968 KB
testcase_35 AC 139 ms
7,968 KB
testcase_36 AC 140 ms
8,116 KB
testcase_37 AC 140 ms
8,116 KB
testcase_38 AC 139 ms
8,304 KB
testcase_39 AC 140 ms
8,168 KB
testcase_40 AC 140 ms
8,040 KB
testcase_41 AC 140 ms
7,976 KB
testcase_42 AC 139 ms
8,028 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0