結果
問題 | No.370 道路の掃除 |
ユーザー |
![]() |
提出日時 | 2018-02-22 17:24:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 801 bytes |
コンパイル時間 | 944 ms |
コンパイル使用メモリ | 89,152 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 21:09:14 |
合計ジャッジ時間 | 1,929 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cstring> #include <math.h> #include <cmath> #include <limits.h> #include <map> #include <set> #include <queue> #include <algorithm> #include <functional> #include <stdio.h> using namespace std; long long MOD = 1000000007; int main() { int N,M; cin >> N >> M; vector<long long> V(M); for ( int i = 0; i < M; i++ ) { cin >> V[i]; } sort( V.begin(), V.end() ); long long ans = LLONG_MAX; for ( int i = 0; i <= M-N; i++ ) { long long a; long long x = V[i]; long long y = V[i+N-1]; if ( x*y >= 0 ) { a = max( abs(x), abs(y) ); } else { a = min(abs(x),abs(y))*2 + max(abs(x),abs(y)); } ans = min( ans, a ); } cout << ans << endl; return 0; }