結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー KKT89KKT89
提出日時 2020-10-10 04:12:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 203,988 KB
実行使用メモリ 6,336 KB
最終ジャッジ日時 2023-09-27 21:03:04
合計ジャッジ時間 14,884 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 54 ms
6,008 KB
testcase_19 AC 56 ms
5,908 KB
testcase_20 AC 31 ms
4,568 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 35 ms
4,824 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 43 ms
5,360 KB
testcase_25 AC 31 ms
4,948 KB
testcase_26 AC 13 ms
4,380 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 56 ms
6,156 KB
testcase_29 AC 59 ms
6,160 KB
testcase_30 AC 56 ms
6,168 KB
testcase_31 AC 58 ms
6,144 KB
testcase_32 AC 58 ms
6,132 KB
testcase_33 AC 56 ms
6,196 KB
testcase_34 AC 56 ms
6,216 KB
testcase_35 AC 57 ms
6,136 KB
testcase_36 AC 56 ms
6,156 KB
testcase_37 AC 57 ms
6,108 KB
testcase_38 AC 57 ms
6,224 KB
testcase_39 AC 58 ms
6,200 KB
testcase_40 AC 58 ms
6,136 KB
testcase_41 AC 58 ms
6,272 KB
testcase_42 AC 56 ms
6,336 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<ll,ll>> v(n);
	ll sum=0;
	for(int i=0;i<n;i++){
		cin >> v[i].first;
	}
	for(int i=0;i<n;i++){
		cin >> v[i].second;
		sum+=v[i].second;
	}
	sort(v.begin(), v.end());
	sum=(sum+1)/2;
	for(int i=0;i<n;i++){
		if(sum>v[i].second){
			sum-=v[i].second;
		}
		else{
			sum=v[i].first;
			break;
		}
	}
	ll res=0;
	for(int i=0;i<n;i++){
		res+=v[i].second*abs(sum-v[i].first);
	}
	cout << sum << " " << res << endl;
}
0