結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー carrot46carrot46
提出日時 2020-10-15 23:27:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 171,484 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2023-09-28 01:30:37
合計ジャッジ時間 18,668 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 139 ms
7,492 KB
testcase_19 AC 133 ms
7,316 KB
testcase_20 AC 77 ms
5,412 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 83 ms
5,624 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 110 ms
6,504 KB
testcase_25 AC 80 ms
5,660 KB
testcase_26 AC 29 ms
4,380 KB
testcase_27 AC 9 ms
4,380 KB
testcase_28 AC 145 ms
7,760 KB
testcase_29 AC 147 ms
7,828 KB
testcase_30 AC 145 ms
7,944 KB
testcase_31 AC 144 ms
7,684 KB
testcase_32 AC 142 ms
7,736 KB
testcase_33 AC 147 ms
7,732 KB
testcase_34 AC 144 ms
7,752 KB
testcase_35 AC 143 ms
7,680 KB
testcase_36 AC 146 ms
7,688 KB
testcase_37 AC 144 ms
7,740 KB
testcase_38 AC 145 ms
7,684 KB
testcase_39 AC 144 ms
7,852 KB
testcase_40 AC 144 ms
7,724 KB
testcase_41 AC 144 ms
7,972 KB
testcase_42 AC 147 ms
7,716 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<48);

int main() {
    cin>>N;
    vec a(N+1, (ll)2e+6), b(N+1, 0), ord(N+1);
    rep(i, N) cin>>a[i];
    rep(i, N) cin>>b[i];
    iota(ALL(ord), 0);
    sort(ALL(ord), [&](int x, int y){return a[x] < a[y];});
    ll res(0);
    rep(i, N) {
        int id(ord[i]), nx(ord[i+1]);
        res += b[nx] * (a[nx] - a[ord[0]]);
        b[nx] += b[id];
    }
    int res_id(-1);
    rep(i, N){
        int id(ord[i]), nx(ord[i+1]);
        if(b[id] > b[ord[N]] - b[id]) {res_id = id; break;}
        res += (a[nx] - a[id]) * (b[id] * 2 - b[ord[N]]);
    }
    cout<<a[res_id]<<' '<<res<<endl;
}
0