結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー どららどらら
提出日時 2020-10-09 21:36:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 176,140 KB
実行使用メモリ 10,764 KB
最終ジャッジ日時 2024-07-20 09:47:41
合計ジャッジ時間 16,058 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 28
権限があれば一括ダウンロードができます

ソースコード

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){
      lhs++;
      v[rhs].second -= v[lhs].second;
    }else{
      rhs--;
      v[lhs].second -= v[rhs].second;
    }
  }

  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