結果
| 問題 | 
                            No.370 道路の掃除
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hogeover30
                         | 
                    
| 提出日時 | 2016-08-24 20:44:47 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 611 bytes | 
| コンパイル時間 | 1,008 ms | 
| コンパイル使用メモリ | 76,128 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-08 02:09:49 | 
| 合計ジャッジ時間 | 2,344 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 34 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n, m; cin>>n>>m;
    vector<int> L(1), R(1);
    for(int i=0; i<m; ++i) {
        int d; cin>>d;
        if (d<0)
            L.push_back(-d);
        else
            R.push_back(d);
    }
    sort(begin(L), end(L));
    sort(begin(R), end(R));
    int res=1<<30;
    for(int k=0; k<=n; ++k) {
        int x=min<int>(k, L.size()-1);
        if (n-x<R.size()) res=min(res, L[x]*2+R[n-x]);
        x=min<int>(k, R.size()-1);
        if (n-x<L.size()) res=min(res, R[x]*2+L[n-x]);
    }
    cout<<res<<endl;
}
            
            
            
        
            
hogeover30