結果
問題 | No.370 道路の掃除 |
ユーザー |
|
提出日時 | 2024-09-21 19:34:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 430 bytes |
コンパイル時間 | 2,141 ms |
コンパイル使用メモリ | 198,704 KB |
最終ジャッジ日時 | 2025-02-24 11:24:38 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll=long long;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);ll N,M;cin>>N>>M;vector<ll> A(M);for(int i=0;i<M;i++)cin>>A[i];sort(A.begin(),A.end());ll an=1e18;for(int i=0;i<M-N+1;i++){ll L=A[i];ll R=A[i+N-1];an=min(an,abs(L)+R-L);an=min(an,abs(R)+R-L);}cout<<an<<endl;}