結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー abc3abc3
提出日時 2020-10-10 02:03:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 205,848 KB
実行使用メモリ 9,608 KB
最終ジャッジ日時 2023-09-27 20:55:20
合計ジャッジ時間 15,994 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 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 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 120 ms
9,100 KB
testcase_19 AC 115 ms
8,736 KB
testcase_20 AC 67 ms
6,280 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 73 ms
6,844 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 93 ms
7,860 KB
testcase_25 AC 75 ms
6,524 KB
testcase_26 AC 25 ms
4,476 KB
testcase_27 AC 9 ms
4,380 KB
testcase_28 AC 126 ms
9,348 KB
testcase_29 AC 131 ms
9,484 KB
testcase_30 AC 124 ms
9,336 KB
testcase_31 AC 133 ms
9,540 KB
testcase_32 AC 130 ms
9,260 KB
testcase_33 AC 124 ms
9,456 KB
testcase_34 AC 127 ms
9,264 KB
testcase_35 AC 126 ms
9,520 KB
testcase_36 AC 127 ms
9,420 KB
testcase_37 AC 127 ms
9,212 KB
testcase_38 AC 129 ms
9,260 KB
testcase_39 AC 128 ms
9,412 KB
testcase_40 AC 133 ms
9,404 KB
testcase_41 AC 125 ms
9,420 KB
testcase_42 AC 130 ms
9,608 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
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; }

const int INF=1001001001;
const int mod = 1000000007;

int main() {
  int N;
  cin>>N;
  vector<int64_t>A(N),B(N);
  for(int i=0;i<N;i++){cin>>A[i];}
  for(int i=0;i<N;i++){cin>>B[i];}
  vector<pair<int64_t,int64_t>>t(N);
  for(int i=0;i<N;i++){
    t[i]=make_pair(A[i],B[i]);
  }
  sort(t.begin(),t.end());
  auto f=[&](int64_t x){
    int64_t sum=0;
    for(int i=0;i<N;i++){
      sum+=t[i].second*abs(x-t[i].first);
    }
    return sum;
  };
  int64_t sum=0;
  for(int i=0;i<N;i++){
    sum+=t[i].second;
  }
  sum=(sum)/2;
  int64_t d=0;
  int r=0;
  for(int i=0;i<N;i++){
    d+=t[i].second;
    if(d>=sum){r=i;break;}
  }//cout<<r<<endl;
  int64_t p=t[r].first;
  cout<<p<<" "<<f(p)<<endl;
  return 0;
}
0