結果

問題 No.1522 Unfairness
ユーザー lam6er
提出日時 2025-03-20 20:39:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,298 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 77,068 KB
最終ジャッジ日時 2025-03-20 20:39:25
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    M = int(input[1])
    A = list(map(int, input[2:2+N]))
    A.sort(reverse=True)
    
    max_O = 0
    
    for k in range(0, N//2 + 1):
        if 2*k > N:
            continue
        if 2*k ==0:
            current_O =0
            if 0 <= M:
                max_O = max(max_O, current_O)
            continue
        
        selected = A[:2*k]
        sum_total = sum(selected)
        O = sum(selected[i] for i in range(0, 2*k, 2))
        E = sum_total - O
        D = O - E
        
        if D <= M:
            if O > max_O:
                max_O = O
            continue
        
        deltas = []
        for i in range(k):
            a = selected[2*i]
            b = selected[2*i +1]
            deltas.append(a - b)
        
        deltas.sort(reverse=True)
        
        required = D - M
        current_sum = 0
        count = 0
        for delta in deltas:
            current_sum += delta
            count +=1
            if current_sum * 2 >= required:
                break
        
        if current_sum *2 >= required:
            new_O = O - current_sum
            if new_O > max_O:
                max_O = new_O
    
    print(max_O)

if __name__ == '__main__':
    main()
0