結果
問題 |
No.370 道路の掃除
|
ユーザー |
👑 |
提出日時 | 2020-03-18 16:34:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 497 bytes |
コンパイル時間 | 741 ms |
コンパイル使用メモリ | 74,448 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-14 02:16:43 |
合計ジャッジ時間 | 2,073 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n,m;cin>>n>>m; int ans = 100000000; vector<int> A(m); for(int i = 0; m > i; i++){ cin>>A[i]; } sort(A.begin(),A.end()); for(int i = 0; m-n >= i; i++){ int t = A[i+n-1]-A[i]; if(A[i+n-1] <= 0){ ans = min(ans,0-A[i]); }else if(A[i] >= 0){ ans = min(ans,A[i+n-1]); }else{ ans = min(ans,min(abs(A[i]),abs(A[i+n-1]))*2+max(abs(A[i]),abs(A[i+n-1]))); } } cout << ans << endl; }