結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 136 ms
9,040 KB
testcase_19 AC 131 ms
8,916 KB
testcase_20 AC 75 ms
6,260 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 82 ms
6,728 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 107 ms
7,868 KB
testcase_25 AC 79 ms
6,416 KB
testcase_26 AC 29 ms
4,436 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 142 ms
9,368 KB
testcase_29 AC 140 ms
9,296 KB
testcase_30 AC 143 ms
9,372 KB
testcase_31 AC 142 ms
9,368 KB
testcase_32 AC 141 ms
9,432 KB
testcase_33 AC 140 ms
9,452 KB
testcase_34 AC 141 ms
9,252 KB
testcase_35 AC 142 ms
9,500 KB
testcase_36 AC 141 ms
9,428 KB
testcase_37 AC 142 ms
9,304 KB
testcase_38 AC 141 ms
9,248 KB
testcase_39 AC 142 ms
9,304 KB
testcase_40 AC 140 ms
9,296 KB
testcase_41 AC 141 ms
9,308 KB
testcase_42 AC 141 ms
9,568 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 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+1)/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