結果

問題 No.2693 Sword
ユーザー nikoro256
提出日時 2024-03-22 21:56:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 67,456 KB
最終ジャッジ日時 2024-09-30 11:25:16
合計ジャッジ時間 2,319 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

N,P,K=map(int,input().split())
counttwo=0
ones=[]
dat=[]
for _ in range(N):
    t,b=map(int,input().split())
    if t==2:
        counttwo+=1
    else:
        ones.append(b)
    dat.append([t,b])
ones.sort(reverse=True)
ans=0
for i in range(min(counttwo+1,K+1)):
    use=K-i
    if len(ones)>=use:
        lis=[]
        mul=1
        twocount=0
        count=0
        for j in range(N-1,-1,-1):
            if dat[j][0]==2:
                if twocount<i:
                    mul*=2
                    twocount+=1
                    if mul>10**18:
                        mul=10**18+1
            else:
                lis.append(mul*dat[j][1])
        lis.sort(reverse=True)
        tmp=P*mul+sum(lis[:use])
        if tmp>10**18:
            print(-1)
            exit(0)
        ans=max(ans,tmp)
print(ans)
0