結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー ShibuyapShibuyap
提出日時 2020-10-21 21:40:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,150 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 205,316 KB
実行使用メモリ 6,204 KB
最終ジャッジ日時 2023-09-28 14:26:47
合計ジャッジ時間 15,969 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

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 >> 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[i].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].first;
            minus -= v[now].first;
        }
    }
    cout << arg << ' ';
    cout << ans << endl;
    return 0;
}
 
 
0