結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー |
|
提出日時 | 2022-10-01 06:39:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 684 bytes |
コンパイル時間 | 2,197 ms |
コンパイル使用メモリ | 199,808 KB |
最終ジャッジ日時 | 2025-02-07 20:04:16 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector<pair<ll,ll>> V(N); rep(i,N) cin >> V[i].first; rep(i,N) cin >> V[i].second; sort(V.begin(), V.end()); auto f = [&](ll x) { ll res = 0; for(auto [a, b] : V) res += b * abs(a - x); return res; }; ll cnt = 0, sumB = 0; rep(i,N) sumB += V[i].second; rep(i,N) { cnt += V[i].second; if(cnt >= sumB / 2) { cout << V[i].first << " " << f(V[i].first) << endl; return 0; } } }