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

#BS0000155. Các máy dịch chuyển – bản khó (Teleporters — Hard Version)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các máy dịch chuyển – bản khó (Teleporters — Hard Version)

Teleporters (Hard Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

On a number line there are positions 0,1,…,n+10,1,\ldots,n+1. A teleporter at each position ii with 1≤i≤n1\le i\le n costs aia_i coins to use. Walking one unit to either neighbor costs one coin. Every teleporter can be used at most once, and using one lets you teleport immediately to either endpoint 00 or n+1n+1.

Initially you are at position 00 with cc coins. You may walk and activate teleporters in any order, never exceeding the budget. Maximize the number of distinct teleporters used.

Input

  • The first line contains n,cn,c.
  • The second line contains nn positive integers a1,…,ana_1,\ldots,a_n.

Output

Print the maximum number of teleporters that can be used within budget cc.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤c≤10001\le c\le1000; 1≤ai≤1001\le a_i\le100 for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤c≤1061\le c\le10^6; 1≤ai≤1061\le a_i\le10^6 for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤c≤1091\le c\le10^9; 1≤ai≤1091\le a_i\le10^9 for all 1≤i≤n1\le i\le n.

Examples

Example 1

Input

5 6
1 1 1 1 1

Output

2

Explanation

From 00, walk to position 11 for one coin and activate teleporter 11 for one more. Teleport to 6=n+16=n+1, walk back to 55 for one coin, and activate teleporter 55 for one coin. Thus two teleporters cost 44. Any third unused teleporter costs at least 33 more coins, but only 22 remain, so the maximum is 2.