結果

問題 No.370 道路の掃除
ユーザー Mister
提出日時 2020-04-14 01:59:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 96,124 KB
最終ジャッジ日時 2025-01-09 18:22:07
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

constexpr int INF = 1 << 30;

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<int> xs(m);
    for (auto& x : xs) std::cin >> x;
    std::sort(xs.begin(), xs.end());

    int ans = INF;
    for (int i = 0; i + n <= m; ++i) {
        int l = xs[i], r = xs[i + n - 1];
        ans = std::min(ans, r - l + std::min(std::abs(l), std::abs(r)));
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0