結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー rogi52
提出日時 2020-10-09 21:47:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 172,444 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-07-20 10:31:19
合計ジャッジ時間 13,604 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 36
権限があれば一括ダウンロードができます

ソースコード

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<long double,long double>> p(n);
    rep(i,n) cin>>p[i].first;
    rep(i,n) cin>>p[i].second;
    sort(p.begin(),p.end());
    long double x;
    if(n&1) x = p[n/2].first;
    else x = (p[n/2-1].first+p[n/2].first)/2.0;

    long double fx = 0.0;
    rep(i,n){
        fx += p[i].second * abs(p[i].first - x);
    }
    cout.precision(9);
    cout << x << " " << (int)(fx+0.5) << endl;
    return 0;
}
0