結果
問題 |
No.370 道路の掃除
|
ユーザー |
![]() |
提出日時 | 2016-05-13 22:56:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,277 bytes |
コンパイル時間 | 1,522 ms |
コンパイル使用メモリ | 165,976 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 16:47:26 |
合計ジャッジ時間 | 2,698 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using uint = unsigned int; using vi = vector<int>; using vb = vector<bool>; using vd = vector<double>; using vl = vector<ll>; using vvi = vector<vi>; using vvb = vector<vb>; using vvd = vector<vd>; using vvl = vector<vl>; #define REP(i,n) for(ll i=0; i<(n); ++i) #define FOR(i,b,n) for(ll i=(b); i<(n); ++i) #define ALL(v) (v).begin(), (v).end() int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); ll n, m; cin >> n >> m; vl d(m); REP(i, m) cin >> d[i]; vl fu; REP(i, m) if (d[i] < 0) fu.push_back(d[i]); vl sei; REP(i, m) if (d[i] > 0) sei.push_back(d[i]); REP(i, m) if (d[i] == 0) n--; sort(ALL(sei)); sort(ALL(fu)); reverse(ALL(fu)); if (n <= 0) { cout << 0 << endl; return 0; } if (fu.empty()) { cout << sei[n - 1] << endl; return 0; } if (sei.empty()) { cout << fu[n - 1] << endl; return 0; } ll mi = 100000; if(n-1 < sei.size()) mi = min(mi, sei[n - 1]); if(n-1 < fu.size()) mi = min(mi, -fu[n - 1]); REP(i, fu.size()) REP(j, sei.size()) if(i+j+2 >= n){ mi = min(mi, min(-fu[i] * 2 + sei[j], -fu[i] + sei[j] * 2)); } cout << mi << endl; return 0; }