結果

問題 No.1251 絶対に間違ってはいけない最小化問題
ユーザー kotatsugamekotatsugame
提出日時 2020-10-09 21:26:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 958 ms
コンパイル使用メモリ 76,540 KB
実行使用メモリ 6,496 KB
最終ジャッジ日時 2023-09-27 14:20:19
合計ジャッジ時間 14,627 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 124 ms
6,184 KB
testcase_19 AC 117 ms
5,868 KB
testcase_20 AC 68 ms
4,676 KB
testcase_21 AC 11 ms
4,376 KB
testcase_22 AC 77 ms
4,852 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 97 ms
5,416 KB
testcase_25 AC 73 ms
4,544 KB
testcase_26 AC 27 ms
4,376 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 131 ms
6,348 KB
testcase_29 AC 133 ms
6,176 KB
testcase_30 AC 129 ms
6,336 KB
testcase_31 AC 132 ms
6,496 KB
testcase_32 AC 132 ms
6,168 KB
testcase_33 AC 129 ms
6,216 KB
testcase_34 AC 130 ms
6,332 KB
testcase_35 AC 130 ms
6,172 KB
testcase_36 AC 130 ms
6,164 KB
testcase_37 AC 130 ms
6,328 KB
testcase_38 AC 133 ms
6,268 KB
testcase_39 AC 132 ms
6,168 KB
testcase_40 AC 130 ms
6,272 KB
testcase_41 AC 134 ms
6,168 KB
testcase_42 AC 131 ms
6,280 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/iostream:39,
         次から読み込み:  main.cpp:1:
メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内,
    inlined from ‘int main()’ at main.cpp:32:8:
/usr/local/gcc7/include/c++/12.2.0/ostream:167:25: 警告: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
  167 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:20:20: 備考: ‘x’ はここで定義されています
   20 |         long sum=0,x;
      |                    ^

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
long all;
int A[2<<17],B[2<<17];
main()
{
	cin>>N;
	vector<pair<int,int> >X(N);
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<N;i++)
	{
		X[i]=make_pair(A[i],B[i]);
		all+=B[i];
	}
	sort(X.begin(),X.end());
	long sum=0,x;
	for(pair<int,int>p:X)
	{
		sum+=p.second;
		if(sum*2>=all)
		{
			x=p.first;
			break;
		}
	}
	long ans=0;
	for(int i=0;i<N;i++)ans+=(long)B[i]*abs(x-A[i]);
	cout<<x<<" "<<ans<<endl;
}
0