結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー ShibuyapShibuyap
提出日時 2020-10-21 21:55:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 205,016 KB
実行使用メモリ 6,360 KB
最終ジャッジ日時 2023-09-28 14:27:48
合計ジャッジ時間 18,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 143 ms
5,872 KB
testcase_19 AC 138 ms
5,796 KB
testcase_20 AC 82 ms
4,668 KB
testcase_21 AC 19 ms
4,376 KB
testcase_22 AC 89 ms
4,872 KB
testcase_23 AC 15 ms
4,376 KB
testcase_24 AC 115 ms
5,404 KB
testcase_25 AC 85 ms
4,552 KB
testcase_26 AC 35 ms
4,376 KB
testcase_27 AC 16 ms
4,376 KB
testcase_28 AC 150 ms
6,132 KB
testcase_29 AC 149 ms
6,196 KB
testcase_30 AC 150 ms
6,176 KB
testcase_31 AC 149 ms
6,236 KB
testcase_32 AC 150 ms
6,252 KB
testcase_33 AC 149 ms
6,300 KB
testcase_34 AC 148 ms
6,108 KB
testcase_35 AC 149 ms
6,132 KB
testcase_36 AC 150 ms
6,360 KB
testcase_37 AC 149 ms
6,108 KB
testcase_38 AC 149 ms
6,136 KB
testcase_39 AC 150 ms
6,176 KB
testcase_40 AC 149 ms
6,076 KB
testcase_41 AC 149 ms
6,112 KB
testcase_42 AC 148 ms
6,128 KB
testcase_43 AC 7 ms
4,380 KB
testcase_44 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define yn {puts("YES");}else{puts("NO");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;

    vector<P> v(n);
    rep(i,n){
        cin >> v[i].first;
    }
    rep(i,n){
        cin >> v[i].second;
    }
    sort(v.begin(), v.end());
    ll ans = 1001001001001001001;
    ll arg = -1000000;
    ll sum = 0;
    int now = 0;
    ll plus = 0;
    ll minus = 0;
    for(ll i = -1000000; i <= 1000000; i++){
        
        if(i == -1000000){
            rep(j,n){
                sum += v[j].second * abs(i - v[j].first);
                minus += v[j].second;
            }
        }else{
            sum += plus - minus;
        }
        if(ans > sum){
            ans = sum;
            arg = i;
        }
        // ans = min(ans, sum);
        while(now < n && v[now].first == i){
            plus += v[now].second;
            minus -= v[now].second;
            now++;
        }
        /*
        if(-5 <= i && i <= 5){
            cout << i << ' ' << sum << ' ' << plus << ' ' << minus << endl;
        }
        */
    }
    cout << arg << ' ';
    cout << ans << endl;
    return 0;
}
 
 
 
0