結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー shiomusubi496shiomusubi496
提出日時 2020-10-09 22:29:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 170,328 KB
実行使用メモリ 6,436 KB
最終ジャッジ日時 2023-09-27 18:17:13
合計ジャッジ時間 15,383 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 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 1 ms
4,376 KB
testcase_18 AC 124 ms
5,928 KB
testcase_19 AC 123 ms
5,960 KB
testcase_20 AC 67 ms
4,588 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 75 ms
4,816 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 96 ms
5,496 KB
testcase_25 AC 70 ms
5,200 KB
testcase_26 AC 26 ms
4,380 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 127 ms
6,152 KB
testcase_29 AC 131 ms
6,188 KB
testcase_30 AC 129 ms
6,108 KB
testcase_31 AC 130 ms
6,112 KB
testcase_32 AC 132 ms
6,248 KB
testcase_33 AC 129 ms
6,152 KB
testcase_34 AC 130 ms
6,436 KB
testcase_35 AC 131 ms
6,344 KB
testcase_36 AC 131 ms
6,340 KB
testcase_37 AC 134 ms
6,192 KB
testcase_38 AC 129 ms
6,156 KB
testcase_39 AC 129 ms
6,164 KB
testcase_40 AC 129 ms
6,104 KB
testcase_41 AC 131 ms
6,436 KB
testcase_42 AC 130 ms
6,224 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,sum=0;
  cin>>N;
  vector<pair<int,int>> A(N);
  for(pair<int,int> &p:A)cin>>p.first;
  for(pair<int,int> &p:A)cin>>p.second,sum+=p.second;
  sort(A.begin(),A.end());
  int cnt=0;
  for(int i=0;i<N;i++)cnt+=abs(A[0].first-A[i].first)*A[i].second;
  int ans=cnt,idx=A[0].first,n=A[0].second;sum-=A[0].second;
  for(int i=1;i<N;i++){
    cnt+=(A[i].first-A[i-1].first)*(n-sum);
    if(ans>cnt)ans=cnt,idx=A[i].first;
    n+=A[i].second;
    sum-=A[i].second;
  }
  cout<<idx<<' '<<ans<<endl;
}
0