結果

問題 No.2799 Cut and Eat
ユーザー 👑 rin204
提出日時 2024-06-28 23:53:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 429 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 52,352 KB
最終ジャッジ日時 2024-06-28 23:53:20
合計ジャッジ時間 2,639 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
all_ = sum(A)
ans = 0
t = 0
for a in A:
    if a > k:
        continue
    if t == 0:
        ans += a
    else:
        ans -= a
    t ^= 1

odd = len([a for a in A if a > k and a % 2 == 1])
even = len([a for a in A if a > k and a % 2 == 0])

t ^= even & 1

if t == 0:
    ans -= odd & 1
else:
    ans += odd & 1
print((all_ + ans) // 2)
0