結果
問題 | No.1251 絶対に間違ってはいけない最小化問題 |
ユーザー |
👑 ![]() |
提出日時 | 2020-08-18 02:21:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 822 bytes |
コンパイル時間 | 1,027 ms |
コンパイル使用メモリ | 78,984 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-07-20 06:21:22 |
合計ジャッジ時間 | 14,490 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#include<iostream>#include<algorithm>#include<vector>using namespace std;using ll = long long;int main() {ll N;vector<ll> A(200000), B(200000);ll B_sum = 0;ll Med;ll flag = 1, count = 0;ll argx = 0, fx = 0;vector<pair<ll,ll>> P(200000,make_pair(0,0));cin >> N;for (int i = 0; i < N; i++) {cin >> A.at(i);}for (int i = 0; i < N; i++) {cin >> B.at(i);B_sum += B.at(i);}Med = (B_sum + 1) / 2;for (int i = 0; i < N; i++) {P.at(i) = make_pair(A.at(i), B.at(i));}sort(P.begin(), P.end());for (int i = 0; i < P.size(); i++) {count += P.at(i).second;if ((flag == 1) && count >= Med) {flag = 0;argx = P.at(i).first;}}for (int i = 0; i < P.size(); i++) {fx += P.at(i).second * abs(argx - P.at(i).first);}cout << argx << " " << fx << endl;}