結果
問題 | No.2799 Cut and Eat |
ユーザー |
|
提出日時 | 2024-06-28 23:10:08 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 611 bytes |
コンパイル時間 | 2,785 ms |
コンパイル使用メモリ | 248,220 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 23:10:14 |
合計ジャッジ時間 | 3,904 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h> using namespace std; using LL = long long; const int mxn = 105; int n, k, a[mxn]; int f(int x) { return (x <= k) ? x : x / 2; } struct node { int delta, id; } b[mxn]; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) { b[i] = { f(a[i]) - (a[i] - f(a[i])), i }; } sort(b + 1, b + n + 1, [&](const node &lhs, const node &rhs) { return lhs.delta > rhs.delta; }); LL ans = 0; for (int i = 1; i <= n; ++i) { int p = b[i].id; if (i & 1) ans += f(a[p]); else ans += a[p] - f(a[p]); } printf("%lld\n", ans); return 0; }