結果

問題 No.370 道路の掃除
ユーザー ldsyb
提出日時 2017-06-17 15:35:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 75,508 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-01 09:33:24
合計ジャッジ時間 1,543 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

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++) if(n - i < r.size()){
		int dist = min(2 * l[i] + r[n - i], l[i] + 2 * r[n - i]);
		ans = min(ans, dist);
	}
	cout << ans << endl;
}
0