結果

問題 No.370 道路の掃除
ユーザー ldsybldsyb
提出日時 2017-06-17 15:13:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 520 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 75,020 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 17:30:13
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 WA -
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,676 KB
testcase_11 WA -
testcase_12 AC 2 ms
6,676 KB
testcase_13 WA -
testcase_14 AC 2 ms
6,676 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
6,676 KB
testcase_20 WA -
testcase_21 AC 2 ms
6,676 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 WA -
testcase_27 AC 2 ms
6,676 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
6,676 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int abs(int a){
	return 0 <= a ? a : -a;
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> l, r;
	while(m--){
		int d;
		cin >> d;
		(d < 0 ? l : r).emplace_back(abs(d));
	}
	l.emplace_back(0);
	r.emplace_back(0);
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	int ans = 1 << 30;
	for(int i = 0; i < l.size(); i++){
		int dist = min(2 * l[i] + r[n - i], l[i] + 2 * r[n - i]);
		ans = min(ans, dist);
	}
	cout << ans << endl;
}
0