結果
| 問題 | No.370 道路の掃除 |
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2016-07-22 21:25:28 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 704 bytes |
| 記録 | |
| コンパイル時間 | 998 ms |
| コンパイル使用メモリ | 173,492 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-03-08 16:06:49 |
| 合計ジャッジ時間 | 1,979 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N, M;
cin>> N>> M;
vector<int> D(M);
for(int i=0; i<M; i++){
cin>> D[i];
}
sort(D.begin(), D.end());
vector<int> po, ne;
for(int i=0; i<M; i++){
if(D[i]>=0) po.push_back(D[i]);
else ne.push_back(D[i]);
}
reverse(ne.begin(), ne.end());
vector<int> dL(M+1, 1e8), dR(M+1, 1e8);
dL[0]=dR[0]=0;
for(int i=1; i<=ne.size(); i++) dL[i]=-(ne[i-1]);
for(int i=1; i<=po.size(); i++) dR[i]=po[i-1];
int ans=1e8;
for(int k=0; k<=N; k++){
ans=min(ans, min(dL[k]*2+dR[N-k], dL[k]+dR[N-k]*2));
}
cout<< ans<< endl;
return 0;
}
ikd