結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー chocoruskchocorusk
提出日時 2020-10-09 21:30:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 1,359 ms
コンパイル使用メモリ 132,148 KB
実行使用メモリ 7,908 KB
最終ジャッジ日時 2023-09-27 14:48:34
合計ジャッジ時間 15,137 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,448 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
5,360 KB
testcase_03 AC 2 ms
5,400 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
5,380 KB
testcase_09 AC 2 ms
5,456 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
5,456 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 124 ms
7,372 KB
testcase_19 AC 124 ms
7,220 KB
testcase_20 AC 70 ms
5,700 KB
testcase_21 AC 12 ms
5,704 KB
testcase_22 AC 77 ms
5,640 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 100 ms
6,444 KB
testcase_25 AC 74 ms
6,412 KB
testcase_26 AC 26 ms
5,676 KB
testcase_27 AC 10 ms
5,708 KB
testcase_28 AC 131 ms
7,752 KB
testcase_29 AC 129 ms
7,816 KB
testcase_30 AC 131 ms
7,636 KB
testcase_31 AC 131 ms
7,640 KB
testcase_32 AC 136 ms
7,800 KB
testcase_33 AC 131 ms
7,796 KB
testcase_34 AC 131 ms
7,772 KB
testcase_35 AC 128 ms
7,680 KB
testcase_36 AC 135 ms
7,752 KB
testcase_37 AC 131 ms
7,828 KB
testcase_38 AC 127 ms
7,704 KB
testcase_39 AC 133 ms
7,640 KB
testcase_40 AC 128 ms
7,884 KB
testcase_41 AC 132 ms
7,908 KB
testcase_42 AC 132 ms
7,908 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    ll a[200010], b[200020];
    vector<P> v(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
        v[i].first=a[i];
    }
    ll sb=0;
    for(int i=0; i<n; i++){
        cin>>b[i];
        sb+=b[i];
        v[i].second=b[i];
    }
    sort(v.begin(), v.end());
    for(int i=0; i<n; i++){
        a[i]=v[i].first, b[i]=v[i].second;
    }
    ll s=0;
    ll a0=a[0];
    for(int i=0; i<n; i++){
        s+=b[i];
        if(-sb+2*s>=0){
            a0=a[i];break;
        }
    }
    cout<<a0<<" ";
    ll ans=0;
    for(int i=0; i<n; i++){
        ans+=b[i]*abs(a[i]-a0);
    }
    cout<<ans<<endl;
    return 0;
}
0