結果

問題 No.393 2本の竹
ユーザー mkawa2
提出日時 2020-04-15 08:32:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 196 ms / 1,000 ms
コード長 1,183 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 82,852 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-10-01 18:38:47
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    def ok(c,i=0,s=0):
        if cs[c]>n1+n2:return False
        if s>n1:return False
        if cs[c]-n2<=s:return True
        if i==c:return False
        if ok(c,i+1,s) or ok(c,i+1,s+aa[i]):return True

    for _ in range(II()):
        n1,n2=MI()
        m=II()
        aa=LI()
        if n1>n2:n1,n2=n2,n1
        aa.sort()
        cs=[0]
        for a in aa:cs.append(cs[-1]+a)
        l=-1
        r=m+1
        while l+1<r:
            c=(l+r)//2
            if ok(c):l=c
            else:r=c
        print(l)

main()
0