結果

問題 No.2799 Cut and Eat
ユーザー askr58
提出日時 2024-06-28 22:37:48
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 5,514 ms
コンパイル使用メモリ 310,916 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-28 22:37:55
合計ジャッジ時間 5,708 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;

int main()
{
    int n;
    ll k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    int cnt=0;
    for(int i=0;i<n;i++)if(a[i]<=k)cnt++;
    int cnt2=0;
    for(int i=cnt;i<n;i++)if(a[i]%2==0)cnt2++;
    ll ans=0;
    for(int i=cnt-1;i>=0;i-=2)ans+=a[i];
    if((cnt+cnt2)&1){
        ans+=(n-cnt-cnt2+1)/2;
        for(int i=cnt;i<n;i++)ans+=a[i]/2;
    }else{
        ans+=(n-cnt-cnt2)/2;
        for(int i=cnt;i<n;i++)ans+=a[i]/2;
    }
    cout<<ans<<endl;

    return 0;
}
0