結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー leaf_1415leaf_1415
提出日時 2020-10-09 21:39:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 78,472 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2023-09-27 15:45:59
合計ジャッジ時間 14,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,496 KB
testcase_01 AC 2 ms
7,456 KB
testcase_02 AC 2 ms
7,644 KB
testcase_03 AC 3 ms
7,684 KB
testcase_04 AC 2 ms
7,608 KB
testcase_05 AC 2 ms
7,616 KB
testcase_06 AC 2 ms
7,736 KB
testcase_07 AC 2 ms
7,560 KB
testcase_08 AC 2 ms
7,652 KB
testcase_09 AC 3 ms
7,436 KB
testcase_10 AC 2 ms
7,516 KB
testcase_11 AC 2 ms
7,452 KB
testcase_12 AC 2 ms
7,496 KB
testcase_13 AC 2 ms
7,448 KB
testcase_14 AC 2 ms
7,444 KB
testcase_15 AC 2 ms
7,452 KB
testcase_16 AC 2 ms
7,448 KB
testcase_17 AC 2 ms
7,496 KB
testcase_18 AC 55 ms
9,528 KB
testcase_19 AC 54 ms
9,476 KB
testcase_20 AC 31 ms
9,096 KB
testcase_21 AC 6 ms
7,688 KB
testcase_22 AC 33 ms
9,292 KB
testcase_23 AC 5 ms
7,736 KB
testcase_24 AC 43 ms
9,476 KB
testcase_25 AC 32 ms
9,228 KB
testcase_26 AC 13 ms
8,200 KB
testcase_27 AC 5 ms
7,748 KB
testcase_28 AC 56 ms
9,888 KB
testcase_29 AC 57 ms
9,612 KB
testcase_30 AC 60 ms
9,648 KB
testcase_31 AC 55 ms
9,604 KB
testcase_32 AC 59 ms
9,664 KB
testcase_33 AC 56 ms
9,604 KB
testcase_34 AC 58 ms
9,608 KB
testcase_35 AC 55 ms
9,648 KB
testcase_36 AC 57 ms
9,604 KB
testcase_37 AC 56 ms
9,652 KB
testcase_38 AC 54 ms
9,716 KB
testcase_39 AC 57 ms
9,672 KB
testcase_40 AC 55 ms
9,600 KB
testcase_41 AC 56 ms
9,672 KB
testcase_42 AC 56 ms
9,800 KB
testcase_43 AC 3 ms
7,452 KB
testcase_44 AC 2 ms
7,456 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:47: warning: ‘c’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  for(int i = 1; i <= n; i++) ans += b[i] * abs(c - a[i]);
                                            ~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[200005], b[200005];
P p[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	
	llint sum = 0;
	for(int i = 1; i <= n; i++) p[i] = P(a[i], b[i]), sum += b[i];
	sort(p+1, p+n+1);
	
	llint s = 0, c;
	for(int i = 1; i <= n; i++){
		s += p[i].second;
		if(s*2 >= sum){
			c = p[i].first;
			break;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++) ans += b[i] * abs(c - a[i]);
	cout << c << " " << ans << endl;
	
	return 0;
}
0