結果
| 問題 |
No.370 道路の掃除
|
| コンテスト | |
| ユーザー |
めうめう🎒
|
| 提出日時 | 2016-05-13 22:37:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 944 bytes |
| コンパイル時間 | 823 ms |
| コンパイル使用メモリ | 75,904 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-14 16:43:21 |
| 合計ジャッジ時間 | 1,721 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)
int main() {
int n,m;
int where[1001] = {};
int migi[1001] = {},hida[1001] = {},s = 0;
for(int i = 1;i < 1001;i++){
migi[i] = INF / 2;
hida[i] = INF / 2;
}
cin >> n >> m;
for(int i = 0;i < m;i++){
cin >> where[i];
}
sort(where,where + m);
int now = 1,how = 0;
for(int i = 0;i < m;i++){
if(where[i] < 0) how++;
if(where[i] == 0) s++;
}
for(int i = 0;i < m;i++){
if(where[i] > 0){
migi[now] = where[i];
now++;
}else{
hida[how] = abs(where[i]);
how--;
}
}
int ans = INF;
for(int i = 0;i <= n;i++){
ans = min(ans,min(2*migi[i] + hida[n - s - i],2*hida[i] + migi[n - s - i]));
}
cout << ans << endl;
return 0;
}
めうめう🎒