結果

問題 No.393 2本の竹
ユーザー rpy3cpprpy3cpp
提出日時 2016-07-14 01:59:53
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 792 bytes
コンパイル時間 264 ms
使用メモリ 84,932 KB
最終ジャッジ日時 2022-12-14 17:19:05
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 81 ms
80,420 KB
testcase_01 AC 79 ms
80,468 KB
testcase_02 AC 81 ms
80,440 KB
testcase_03 AC 77 ms
80,328 KB
testcase_04 AC 78 ms
80,292 KB
testcase_05 AC 75 ms
80,460 KB
testcase_06 AC 75 ms
80,452 KB
testcase_07 AC 78 ms
80,508 KB
testcase_08 AC 81 ms
80,756 KB
testcase_09 AC 190 ms
84,932 KB
testcase_10 AC 99 ms
84,596 KB
testcase_11 AC 108 ms
83,436 KB
testcase_12 AC 126 ms
83,868 KB
testcase_13 AC 98 ms
82,132 KB
testcase_14 AC 89 ms
81,664 KB
testcase_15 AC 76 ms
80,556 KB
testcase_16 AC 82 ms
82,800 KB
testcase_17 AC 77 ms
80,532 KB
testcase_18 AC 77 ms
79,972 KB
testcase_19 AC 76 ms
80,380 KB
testcase_20 AC 76 ms
80,100 KB
testcase_21 AC 76 ms
79,976 KB
testcase_22 AC 132 ms
84,676 KB
testcase_23 AC 95 ms
82,412 KB
testcase_24 AC 78 ms
80,508 KB
testcase_25 AC 78 ms
80,116 KB
testcase_26 AC 77 ms
80,324 KB
testcase_27 AC 181 ms
83,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    n1, n2 = map(int, input().split())
    m = int(input())
    As = list(map(int, input().split()))
    return n1, n2, m, As

def solve(n1, n2, m, As):
    As.sort()
    cum = 0
    n12 = n1 + n2
    ans = 0
    dp = [0] * (n1 + 1)
    dp[0] = 1
    for a in As:
        cum += a
        if cum > n12:
            return ans
        for pos in range(n1, a - 1, -1):
            if dp[pos - a]:
                dp[pos] = 1
        for pos in range(n1, -1, -1):
            if dp[pos]:
                if pos + n2 < cum:
                    return ans
                else:
                    break
        ans += 1
    return ans

if __name__ == '__main__':
    d = int(input())
    for i in range(d):
        n1, n2, m, As = read_data()
        print(solve(n1, n2, m, As))
0