結果
問題 | No.2799 Cut and Eat |
ユーザー |
![]() |
提出日時 | 2024-07-05 16:46:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 687 bytes |
コンパイル時間 | 1,993 ms |
コンパイル使用メモリ | 195,020 KB |
最終ジャッジ日時 | 2025-02-22 02:14:01 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | scanf("%d", a + i); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, k, a[N]; long long ans; struct node { int hs, cst, ts; bool operator<(const node &_x) { return cst > _x.cst; } } b[N]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%d", a + i); int v; if (a[i] <= k) v = a[i]; else v = a[i] / 2; b[i].hs = v, b[i].ts = a[i] - v; b[i].cst = b[i].hs - b[i].ts; } sort(b + 1, b + n + 1); for (int i = 1; i <= n; i++) if (i & 1) ans += b[i].hs; else ans += b[i].ts; cout << ans << endl; return 0; }