結果
問題 | No.370 道路の掃除 |
ユーザー |
![]() |
提出日時 | 2016-05-24 22:29:46 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 891 bytes |
コンパイル時間 | 1,188 ms |
コンパイル使用メモリ | 159,760 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 16:57:51 |
合計ジャッジ時間 | 2,123 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> #define rep(x, to) for (int x = 0; x < (to); x++) #define REP(x, a, to) for (int x = (a); x < (to); x++) #define EPS (1e-14) #define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl; #define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;} using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef complex<double> Complex; typedef vector< vector<int> > Mat; int N, M; int D[1005]; int ans = 1e+9 + 7; void solve() { sort(D + 1, D + M + 1); for (int i = N; i <= M; i++) { int p = D[i - N + 1]; int q = D[i]; if (p > 0) { ans = min(ans, (q - p) + abs(p)); } else if (q < 0) { ans = min(ans, (q - p) + abs(q)); } else { ans = min(ans, (q - p) + min(abs(p), abs(q))); } } cout << ans << endl; } int main() { cin >> N >> M; rep(i, M) cin >> D[i + 1]; solve(); return 0; }