結果

問題 No.370 道路の掃除
ユーザー はむこはむこ
提出日時 2016-05-13 22:40:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 1,147 ms
コンパイル使用メモリ 149,384 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-04 19:27:53
合計ジャッジ時間 2,319 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 2 ms
4,388 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long; using ld = long double; using vll = vector<ll>; using vld = vector<ld>;

static const long long INF = 1e18;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    vll a(m); rep(i, a.size()) cin >> a[i];
    sort(all(a));
    ll negnum = (ll)(upper_bound(all(a), 0) - a.begin());
    ll posnum = m - negnum;

    ll ret = INF;
    rep(j, n + 1) { // j個正のを取る
        if (j > posnum || n - j > negnum) continue;
        ll sp = 0; if (j != 0) sp = +a[negnum+j-1];
        ll sn = 0; if (j != n) sn = -a[negnum+j-n];
        chmin(ret, sp + sn * 2);
        chmin(ret, sn + sp * 2);
    }

    cout << ret << endl;
           
    return 0;
}          
0