結果

問題 No.370 道路の掃除
ユーザー yy
提出日時 2016-05-14 17:20:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 574 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 68,864 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-14 16:54:05
合計ジャッジ時間 1,469 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>

using namespace std;

int N, M, D[1000];

void solve() {
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) scanf("%d", &D[i]);
    sort(D, D + M);
    int ans = INT_MAX;
    for (int i = 0; i < M - N + 1; i++) {
        if (D[i + N - 1] <= 0) ans = min(ans, -D[i]);
        else if (D[i] >= 0) ans = min(ans, D[i + N - 1]);
        else ans = min(ans, min(-D[i], D[i + N - 1]) * 2 + max(-D[i], D[i + N - 1]));
    }
    printf("%d\n", ans);
}

int main() {
    solve();
    return 0;
}
0