結果
問題 | No.393 2本の竹 |
ユーザー | mkawa2 |
提出日時 | 2020-04-15 08:32:05 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 996 ms / 1,000 ms |
コード長 | 1,183 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-10-01 18:38:42 |
合計ジャッジ時間 | 3,926 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
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()