結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー 👑 KazunKazun
提出日時 2020-08-18 02:21:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 79,352 KB
実行使用メモリ 9,412 KB
最終ジャッジ日時 2023-09-27 12:13:49
合計ジャッジ時間 14,194 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,272 KB
testcase_01 AC 9 ms
9,280 KB
testcase_02 AC 8 ms
9,252 KB
testcase_03 AC 8 ms
9,088 KB
testcase_04 AC 8 ms
9,412 KB
testcase_05 AC 10 ms
9,152 KB
testcase_06 AC 8 ms
9,324 KB
testcase_07 AC 9 ms
9,272 KB
testcase_08 AC 8 ms
9,264 KB
testcase_09 AC 8 ms
9,348 KB
testcase_10 AC 10 ms
9,152 KB
testcase_11 AC 9 ms
9,320 KB
testcase_12 AC 9 ms
9,128 KB
testcase_13 AC 10 ms
9,408 KB
testcase_14 AC 9 ms
9,216 KB
testcase_15 AC 8 ms
9,096 KB
testcase_16 AC 8 ms
9,096 KB
testcase_17 AC 10 ms
9,256 KB
testcase_18 AC 121 ms
9,152 KB
testcase_19 AC 117 ms
9,268 KB
testcase_20 AC 72 ms
9,352 KB
testcase_21 AC 18 ms
9,264 KB
testcase_22 AC 78 ms
9,096 KB
testcase_23 AC 15 ms
9,364 KB
testcase_24 AC 100 ms
9,328 KB
testcase_25 AC 73 ms
9,192 KB
testcase_26 AC 35 ms
9,256 KB
testcase_27 AC 17 ms
9,340 KB
testcase_28 AC 125 ms
9,252 KB
testcase_29 AC 127 ms
9,128 KB
testcase_30 AC 127 ms
9,336 KB
testcase_31 AC 125 ms
9,336 KB
testcase_32 AC 129 ms
9,128 KB
testcase_33 AC 126 ms
9,388 KB
testcase_34 AC 131 ms
9,088 KB
testcase_35 AC 128 ms
9,336 KB
testcase_36 AC 128 ms
9,200 KB
testcase_37 AC 131 ms
9,084 KB
testcase_38 AC 130 ms
9,328 KB
testcase_39 AC 131 ms
9,212 KB
testcase_40 AC 130 ms
9,272 KB
testcase_41 AC 136 ms
9,084 KB
testcase_42 AC 129 ms
9,216 KB
testcase_43 AC 9 ms
9,284 KB
testcase_44 AC 10 ms
9,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0