結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー outlineoutline
提出日時 2020-10-09 23:00:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,668 bytes
コンパイル時間 1,369 ms
コンパイル使用メモリ 138,620 KB
実行使用メモリ 16,120 KB
最終ジャッジ日時 2023-09-27 19:14:26
合計ジャッジ時間 17,035 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 180 ms
15,464 KB
testcase_19 AC 179 ms
14,876 KB
testcase_20 AC 87 ms
9,976 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 95 ms
10,580 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 137 ms
12,792 KB
testcase_25 AC 94 ms
10,248 KB
testcase_26 AC 27 ms
5,904 KB
testcase_27 AC 9 ms
4,380 KB
testcase_28 AC 206 ms
15,796 KB
testcase_29 AC 201 ms
15,816 KB
testcase_30 AC 197 ms
16,120 KB
testcase_31 AC 196 ms
15,968 KB
testcase_32 AC 196 ms
15,868 KB
testcase_33 AC 190 ms
15,828 KB
testcase_34 AC 200 ms
15,828 KB
testcase_35 AC 192 ms
15,972 KB
testcase_36 AC 193 ms
15,956 KB
testcase_37 AC 190 ms
15,912 KB
testcase_38 AC 197 ms
15,924 KB
testcase_39 AC 186 ms
15,940 KB
testcase_40 AC 187 ms
15,804 KB
testcase_41 AC 189 ms
15,960 KB
testcase_42 AC 197 ms
15,888 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    map<int, int> mp;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        mp[A[i]] = -1;
    }
    for(int i = 0; i < N; ++i)  cin >> B[i];

    int K = 0;
    vector<int> xs;
    for(auto& it : mp){
        it.second = K++;
        xs.emplace_back(it.first);
    }
    vector<ll> sum(K + 1);
    for(int i = 0; i < N; ++i)  sum[mp[A[i]] + 1] += B[i];
    for(int i = 0; i < K; ++i)  sum[i + 1] += sum[i];

    int X = 0;
    for(int i = 1; i <= K; ++i){
        if(sum[i] * 2 >= sum[K]){
            X = i - 1;
            break;
        }
    }
    X = xs[X];
    ll ans = 0;
    for(int i = 0; i < N; ++i)  ans += (ll)B[i] * abs(X - A[i]);
    cout << X << ' ' << ans << '\n';
}
0