結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー どららどらら
提出日時 2020-10-09 21:42:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 173,700 KB
実行使用メモリ 12,436 KB
最終ジャッジ日時 2023-09-27 15:56:37
合計ジャッジ時間 15,487 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 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,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 139 ms
10,740 KB
testcase_19 AC 131 ms
10,428 KB
testcase_20 AC 75 ms
6,900 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 80 ms
6,992 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 106 ms
10,048 KB
testcase_25 AC 75 ms
6,960 KB
testcase_26 AC 30 ms
4,696 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 139 ms
10,548 KB
testcase_29 AC 143 ms
11,112 KB
testcase_30 AC 139 ms
11,484 KB
testcase_31 AC 136 ms
10,492 KB
testcase_32 AC 135 ms
12,436 KB
testcase_33 AC 137 ms
11,604 KB
testcase_34 AC 139 ms
10,476 KB
testcase_35 AC 135 ms
10,956 KB
testcase_36 AC 138 ms
11,208 KB
testcase_37 AC 138 ms
12,172 KB
testcase_38 AC 139 ms
11,744 KB
testcase_39 AC 141 ms
12,252 KB
testcase_40 AC 134 ms
10,792 KB
testcase_41 AC 136 ms
11,548 KB
testcase_42 AC 138 ms
10,740 KB
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,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<ll> A, B;
  rep(i,N){
    ll a;
    cin >> a;
    A.push_back(a);
  }
  rep(i,N){
    ll b;
    cin >> b;
    B.push_back(b);
  }

  vector<pair<ll,ll>> v;
  rep(i,N){
    v.emplace_back(A[i],B[i]);
  }
  sort(ALLOF(v));

  int lhs = 0, rhs = N-1;
  while(lhs != rhs){
    if(v[lhs].second < v[rhs].second){
      v[rhs].second -= v[lhs].second;
      v[lhs].second -= v[lhs].second;
    }else{
      v[lhs].second -= v[rhs].second;
      v[rhs].second -= v[rhs].second;
    }
    if(v[lhs].second == 0) lhs++;
    if(lhs == rhs) break;
    if(v[rhs].second == 0) rhs--;
  }

  ll x = v[lhs].first;
  ll y = 0;
  rep(i,N){
    y += B[i] * abs(x - A[i]);
  }
  
  cout << x << " " << y << endl;
  
  return 0;
}

0