結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー Inazuma_110
提出日時 2020-10-09 22:30:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,343 bytes
コンパイル時間 6,324 ms
コンパイル使用メモリ 382,556 KB
最終ジャッジ日時 2025-01-15 05:15:35
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
// #include <atcoder/all>

using boost::multiprecision::cpp_int;
using namespace std;
// using namespace atcoder;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<p> v(n);
  rep(i, n) cin >> v[i].first;
  rep(i, n) cin >> v[i].second;
  sort(ALL(v));
  long double c;
  if(n % 2 == 1) c = v[n/2].first;
  else c = (long double)(v[n/2].first+v[n/2-1].second)/2.0;

  auto f = [&](long double x){
    long double val = 0;
    rep(i, n){ val += v[i].second*abs(x-v[i].first); }
    return val;
  };

  // long double l = -1e12, r = 1e12;
  // ll count = 1e6;
  // while(count--){
  //   long double c1 = (l*2 + r) / 3;
  //   long double c2 = (l + r*2) / 3;
  //   if(f(c1) > f(c2)) l = c1;
  //   else r = c2;
  // }
  //
  cout << setprecision(15);
  cout << c << ' ' << f(c) << endl;
}
0