結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー |
![]() |
提出日時 | 2020-10-09 22:24:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 181 ms / 2,000 ms |
コード長 | 575 bytes |
コンパイル時間 | 4,995 ms |
コンパイル使用メモリ | 202,516 KB |
最終ジャッジ日時 | 2025-01-15 05:09:21 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<ll> A(n),B(n); vector<pair<ll,ll>> C(n); rep(i,n) cin>>A[i]; rep(i,n) cin>>B[i]; rep(i,n) C[i]={A[i],B[i]}; sort(ALL(C)); vector<ll> s(n+1); rep(i,n) s[i+1]=s[i]+C[i].second; ll m=(s[n]+1)/2; ll x=C[lower_bound(ALL(s),m)-s.begin()-1].first; ll ans=0; rep(i,n){ ans+=C[i].second*abs(C[i].first-x); } cout<<x<<" "<<ans<<endl; return 0; }