結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー kk
提出日時 2020-11-11 00:00:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 888 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 205,700 KB
実行使用メモリ 4,868 KB
最終ジャッジ日時 2023-09-30 00:17:06
合計ジャッジ時間 16,879 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 56 ms
4,380 KB
testcase_20 AC 32 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 35 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 13 ms
4,376 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 60 ms
4,552 KB
testcase_29 WA -
testcase_30 AC 60 ms
4,688 KB
testcase_31 AC 60 ms
4,684 KB
testcase_32 AC 61 ms
4,868 KB
testcase_33 WA -
testcase_34 AC 61 ms
4,564 KB
testcase_35 AC 60 ms
4,620 KB
testcase_36 AC 61 ms
4,580 KB
testcase_37 AC 61 ms
4,624 KB
testcase_38 WA -
testcase_39 AC 61 ms
4,620 KB
testcase_40 AC 60 ms
4,612 KB
testcase_41 AC 60 ms
4,676 KB
testcase_42 WA -
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

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

  int n;
  cin >> n;
  vector<pair<int, int> > v(n);
  
  REP (i, n) cin >> v[i].first;
  REP (i, n) cin >> v[i].second;

  sort(v.begin(), v.end());

  long long total = 0;
  REP (i, n) total += v[i].second;
  
  int m = -1;
  long long diff = total + 1;
  long long pos = total;
  long long neg = 0;
  REP (i, n) {
    pos -= v[i].second;
    if (abs(pos-neg) < diff) {
      diff = abs(pos-neg);
      m = i;
    }
    neg += v[i].second;
  }

  int x = v[m].first;
  long long ret = 0;
  REP (i, n) ret += (long long)v[i].second * abs(v[i].first - x);
  cout << x << " " << ret << endl;
  
  return 0;
}
0