結果
| 問題 |
No.2799 Cut and Eat
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-07-05 16:45:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 677 bytes |
| コンパイル時間 | 2,006 ms |
| コンパイル使用メモリ | 195,976 KB |
| 最終ジャッジ日時 | 2025-02-22 02:13:52 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf("%d", a + i);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, k, a[N], 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;
}
vjudge1