아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Subset Sum

면접 대비

시간 제한4초메모리 제한512 MB

요약
n개의 정수와 상한 c가 주어질 때, 합이 c를 넘지 않으면서 최대가 되는 부분집합의 합을 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

Chiaki has nn integers a_1,a_2,…,a_na\_1, a\_2, \dots, a\_n and another integer cc, and she would like to choose a subset of the nn integers whose sum does not exceed cc. Find the maximum possible sum of the chosen subset.

입력

There are multiple test cases. The first line of the input contains an integer TT (1≤T≤2×1041 \le T \le 2 \times 10^4), indicating the number of test cases. For each test case:

The first line contains two integers nn and cc (1≤n≤2×1041 \le n \leq 2 \times 10^4, 1≤c≤1091 \leq c \leq 10^9). The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \dots, a\_n (1≤a_i≤2×1041 \leq a\_i \leq 2 \times 10^4). 

The sum of all nn does not exceed 2×1042 \times 10^4.

출력

For each test case, output an integer denoting the answer.

예제1

  1. 예제 1

    입력
    3
    3 5
    2 3 4
    3 1
    2 3 4
    3 1000000000
    2 3 4
    
    예상 출력
    5
    0
    9