PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000126. Dãy con dài nhất với giới hạn tổng (Longest Subsequence With Limited Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy con dài nhất với giới hạn tổng (Longest Subsequence With Limited Sum)

Longest Subsequence With Limited Sum

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn positive integers a1,…,ana_1,\ldots,a_n and qq queries, for each limit XjX_j choose a subsequence (delete some entries, retaining the relative order of the remaining entries) with total sum at most XjX_j. Find the maximum possible subsequence length for each query. The empty subsequence of length zero is allowed.

Input

The first line contains n,qn,q. The second line contains nn values aia_i. The third line contains the qq query limits XjX_j.

Output

Print qq space-separated integers, the maximum subsequence length for each query.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤121\le n,q\le 12; 1≤ai,Xj≤1061\le a_i,X_j\le 10^6 for 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.
  • Subtask 2 (30 points): 1≤n,q≤1001\le n,q\le 100; 1≤ai,Xj≤1061\le a_i,X_j\le 10^6 for 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.
  • Subtask 3 (50 points): 1≤n,q≤10001\le n,q\le 1000; 1≤ai,Xj≤1061\le a_i,X_j\le 10^6 for 1≤i≤n1\le i\le n, 1≤j≤q1\le j\le q.

Examples

Input

4 3
4 5 2 1
3 10 21

Output

2 3 4

Explanation

For X=3X=3, the subsequence (2,1)(2,1) has sum 33, while the three smallest values already sum to 7>37>3. For X=10X=10, (4,5,1)(4,5,1) has sum 1010; all four sum to 12>1012>10. For X=21X=21, all four values fit, with total 1212. Therefore print 2 3 4.