結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー hedwig100hedwig100
提出日時 2020-10-10 20:14:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 171,528 KB
実行使用メモリ 7,968 KB
最終ジャッジ日時 2023-09-27 22:35:57
合計ジャッジ時間 14,209 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 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,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 56 ms
7,680 KB
testcase_19 AC 54 ms
7,444 KB
testcase_20 AC 31 ms
5,592 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 34 ms
5,624 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 47 ms
6,480 KB
testcase_25 AC 34 ms
5,624 KB
testcase_26 AC 12 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 60 ms
7,664 KB
testcase_29 AC 60 ms
7,852 KB
testcase_30 AC 59 ms
7,968 KB
testcase_31 AC 60 ms
7,776 KB
testcase_32 AC 59 ms
7,732 KB
testcase_33 AC 60 ms
7,856 KB
testcase_34 AC 60 ms
7,852 KB
testcase_35 AC 61 ms
7,752 KB
testcase_36 AC 58 ms
7,784 KB
testcase_37 AC 62 ms
7,736 KB
testcase_38 AC 60 ms
7,804 KB
testcase_39 AC 60 ms
7,740 KB
testcase_40 AC 58 ms
7,736 KB
testcase_41 AC 60 ms
7,784 KB
testcase_42 AC 60 ms
7,732 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<PL> A(N);
    rep(i,N) cin >> A[i].first;
    rep(i,N) cin >> A[i].second;

    sort(A.begin(),A.end());
    vector<ll> B(N+1,0);
    rep(i,N) B[i+1] = B[i] + A[i].second;
    ll med = B[N]/2 + 1;
    ll a = 0;
    rep(i,N) {
        if (B[i+1] >= med) {
            a = A[i].first;
            break;
        }
    }
    ll ans = 0;
    rep(i,N) {
        ans += A[i].second*abs(a - A[i].first);
    }
    cout << a << ' ' << ans << '\n';
    return 0;
}
0