結果
| 問題 | 
                            No.370 道路の掃除
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-05-13 23:47:24 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 502 bytes | 
| コンパイル時間 | 560 ms | 
| コンパイル使用メモリ | 69,120 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-14 16:48:15 | 
| 合計ジャッジ時間 | 1,495 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 34 | 
ソースコード
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
	int norma, m;
	cin >> norma >> m;
	int dust[m];
	for (int i = 0; i < m; i++) {
		cin >> dust[i];
	}
	sort(dust, dust+m);
	int ans = 0x7FFF;
	for (int i = 0; i <= m - norma; i++) {
		if (dust[i] * dust[i+norma-1] >= 0) {
			ans = min(ans, max(abs(dust[i]), abs(dust[i+norma-1])));
		} else {
			ans = min(ans, abs(dust[i] - dust[i+norma-1]) + min(abs(dust[i]), abs(dust[i+norma-1])));
		}
	}
	cout << ans << endl;
	return 0;
}