結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー iqueue02iqueue02
提出日時 2020-10-17 12:29:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 205,456 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-09-28 07:36:33
合計ジャッジ時間 18,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,360 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,356 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 1 ms
4,360 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,356 KB
testcase_17 AC 1 ms
4,360 KB
testcase_18 AC 121 ms
6,208 KB
testcase_19 AC 116 ms
5,888 KB
testcase_20 AC 66 ms
4,668 KB
testcase_21 AC 11 ms
4,356 KB
testcase_22 AC 73 ms
4,836 KB
testcase_23 AC 8 ms
4,356 KB
testcase_24 AC 95 ms
5,484 KB
testcase_25 AC 71 ms
4,920 KB
testcase_26 AC 26 ms
4,356 KB
testcase_27 AC 8 ms
4,352 KB
testcase_28 AC 126 ms
6,200 KB
testcase_29 AC 134 ms
6,340 KB
testcase_30 AC 127 ms
6,196 KB
testcase_31 AC 125 ms
6,240 KB
testcase_32 AC 125 ms
6,264 KB
testcase_33 AC 126 ms
6,084 KB
testcase_34 AC 127 ms
6,180 KB
testcase_35 AC 125 ms
6,140 KB
testcase_36 AC 125 ms
6,296 KB
testcase_37 AC 126 ms
6,188 KB
testcase_38 AC 125 ms
6,168 KB
testcase_39 AC 127 ms
6,080 KB
testcase_40 AC 126 ms
6,088 KB
testcase_41 AC 126 ms
6,072 KB
testcase_42 AC 125 ms
6,080 KB
testcase_43 AC 1 ms
4,356 KB
testcase_44 AC 1 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main() {
  int n;
  cin >> n;
  vector<pair<ll,ll>> p(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i].second;
    sum += p[i].second;
  }
  sort(p.begin(), p.end());
  sum = (sum + 1) / 2;
  for (int i = 0; i < n; i++) {
    if (sum > p[i].second) sum -= p[i].second;
    else {
      sum = p[i].first;
      break;
    }
  }
  ll res = 0;
  for (int i = 0; i < n; i++) res += p[i].second * abs(p[i].first - sum);
  cout << sum << " " << res << endl;
  return 0;
}
0