結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー rogi52rogi52
提出日時 2022-10-01 06:39:40
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 206,960 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-12-23 11:14:16
合計ジャッジ時間 16,279 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<pair<ll,ll>> V(N);
    rep(i,N) cin >> V[i].first;
    rep(i,N) cin >> V[i].second;
    sort(V.begin(), V.end());
    auto f = [&](ll x) {
        ll res = 0;
        for(auto [a, b] : V) res += b * abs(a - x);
        return res;
    };

    ll cnt = 0, sumB = 0;
    rep(i,N) sumB += V[i].second;
    rep(i,N) {
        cnt += V[i].second;
        if(cnt >= sumB / 2) {
            cout << V[i].first << " " << f(V[i].first) << endl;
            return 0;
        }
    }
}
0