結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define sorted(a) sort(a.begin(), a.end());
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, M;
  cin >> N >> M;
  int D[1000];
  for (int i = 0; i < 1000; i++)
    D[i] = 65535;
  for (int i = 0; i < M; i++)
    cin >> D[i];
  sort(D, D + 1000);

  int dist;
  int ans = 65535;
  for (int i = 0; i + N <= M; i++) {
    dist = D[i+N-1] - D[i] + min(abs(D[i]), abs(D[i+N-1]));
    ans = min(ans, dist);
  }
  cout << ans << endl;
  return 0;
}
0