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