結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー startcppstartcpp
提出日時 2020-10-09 22:16:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 67,768 KB
実行使用メモリ 6,752 KB
最終ジャッジ日時 2023-09-27 17:50:19
合計ジャッジ時間 15,903 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 141 ms
6,624 KB
testcase_19 AC 136 ms
6,220 KB
testcase_20 AC 79 ms
5,068 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 85 ms
5,164 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 111 ms
5,688 KB
testcase_25 AC 82 ms
5,076 KB
testcase_26 AC 30 ms
4,376 KB
testcase_27 AC 10 ms
4,380 KB
testcase_28 AC 148 ms
6,456 KB
testcase_29 AC 147 ms
6,504 KB
testcase_30 AC 149 ms
6,480 KB
testcase_31 AC 146 ms
6,532 KB
testcase_32 AC 147 ms
6,752 KB
testcase_33 AC 147 ms
6,480 KB
testcase_34 AC 147 ms
6,484 KB
testcase_35 AC 148 ms
6,752 KB
testcase_36 AC 148 ms
6,480 KB
testcase_37 AC 147 ms
6,532 KB
testcase_38 AC 146 ms
6,532 KB
testcase_39 AC 147 ms
6,516 KB
testcase_40 AC 147 ms
6,752 KB
testcase_41 AC 147 ms
6,680 KB
testcase_42 AC 147 ms
6,504 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n;
int a[200000];
int b[200000];
int bsum;

int bsuml(int x) {
	int ret = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] <= x) {
			ret += b[i];
		}
	}
	return ret;
}

int f(int x) {
	int ret = 0;
	for (int i = 0; i < n; i++) {
		ret += b[i] * abs(a[i] - x);
	}
	return ret;
}

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) cin >> b[i];
	for (i = 0; i < n; i++) bsum += b[i];
	
	int ok = -1000001, ng = 1000001, mid;
	while (ng - ok >= 2) {
		mid = (ok + ng) / 2;
		if (bsuml(mid) * 2 <= bsum) ok = mid;
		else ng = mid;
	}
	cout << ok + 1 << " " << f(ok + 1) << endl;
	return 0;
}
0