結果

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

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

vector<ll> A, B;

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

    int N;
    cin >> N;
    A.resize(N), B.resize(N);
    rep(i, N) { cin >> A[i]; }

    rep(i, N) { cin >> B[i]; }

    ld med;
    sort(all(A));
    if (A.size() % 2 == 0) {
        med = (A[A.size() / 2 - 1] + A[A.size() / 2]) / 2;
    } else {
        med = A[A.size() / 2];
    }

    ld ans = 0;
    rep(i, N) { ans += B[i] * abs(A[i] - med); }

    cout << fixed << setprecision(5) << med << " " << (ll)ans << endl;
}
0