結果
| 問題 |
No.1251 絶対に間違ってはいけない最小化問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-24 20:34:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 865 bytes |
| コンパイル時間 | 1,599 ms |
| コンパイル使用メモリ | 171,548 KB |
| 実行使用メモリ | 8,284 KB |
| 最終ジャッジ日時 | 2024-07-21 15:37:47 |
| 合計ジャッジ時間 | 15,464 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 WA * 39 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
pll ab[200005];
ll cum[200005];
int main(){
int n;
cin >> n;
rep(i,n) cin >> ab[i].first;
rep(i,n) cin >> ab[i].second;
sort(ab,ab+n);
cum[0] = 0;
rep(i,n) cum[i+1] = cum[i] + ab[i].second;
ll sum = cum[n];
int l = -1, r = n+1;
while(r - l > 1){
int m = (l + r)/2;
if(sum <= 2*cum[m]) r = m;
else l = m;
}
ll x = ab[r].first;
ll ans = 0;
rep(i,n){
ans += ab[i].second * abs(ab[i].first - x);
}
cout << x << " " << ans << endl;
return 0;
}