FortinetOA #1
Madam C.J. Walker's Business Plan
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyBits & Math
There are n distinct items that you can buy and resell. Item i (indices start at 0) costs cost[i], and reselling it yields a profit of 2^i. You have x units of money, each item can be bought at most once, and the total cost of the items bought cannot exceed x. Find the maximum profit you can make. The answer may be large, so output it modulo 10^9+7.
Input
The first line contains two integers n and x; the second line contains n integers cost[0..n−1]. 1≤n≤100000, 1≤cost[i]≤10^9, 1≤x≤10^14.
Output
Output one integer: the maximum profit modulo 10^9+7.
Example 1
Input:
5 70
10 20 14 40 50
Output:
20
Example 2
Input:
2 7
3 4
Output:
3
Example 3
Input:
3 2
1 1 9
Output:
3
Example notes
Example 1: cost=[10,20,14,40,50], x=70. Buying 0,1,2 (cost 44) gives profit 7; 0 and 4 (cost 60) give profit 17; 1 and 4 (cost 70) give profit 18; 2 and 4 (cost 64) give profit 20, which is the maximum. Example 2: buying both items spends exactly 7, for a profit of 1+2=3. Example 3: the item at index 2 is unaffordable; buying the items at indices 0 and 1 gives a profit of 3.
Editorial
Loading solution…