結果

問題 No.370 道路の掃除
ユーザー prog470prog470
提出日時 2017-07-09 00:43:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,221 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 90,924 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 06:44:22
合計ジャッジ時間 2,166 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e15;

using namespace std;

int N, M, D[1010];

int main(){
  cin>>N>>M;
  REP(i,0,M) cin>>D[i];
  sort(D,D+M);
  /*
  int ans = INF;
  REP(l,0,M-N+1){
    int tmp;
    if(D[l] < 0 && 0 < D[l+N-1]){
      tmp = (abs(D[l])+D[l+N-1]) + min(abs(D[l]),D[l+N-1]);
    }else{
      if(D[l+N-1] <= 0) tmp = abs(D[l]);
      else tmp = D[l+N-1];
    }
    fprintf(stderr, "tmp: %d\n", tmp);
    ans = min(ans,tmp);
  }
  cout<<ans<<endl;
  */
  vector<int> L, R;
  L.push_back(0);
  R.push_back(0);
  REP(i,0,M){
    if(D[i] < 0) L.push_back(-D[i]);
    else R.push_back(D[i]);
  }
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  int ans = INF;
  REP(i,0,min(N+1,(int)L.size())){
    ans = min(ans, min(L[i]+R[N-i]*2, L[i]*2+R[N-i]));
  }
  cout<<ans<<endl;
  return 0;
}
0