This page is still under construction.

Parts of this page are still being built. What you see may change.

Mock Competition Marketing

Time limit1sMemory limit1024 MB

Summary
Choose a subset of the 6 ad types; scanning the auction sequence, buy each auction whose type is chosen while budget K allows, and maximize the number bought.
Level

Medium7 of 10

Topics
Brute force, Greedy, Prefix sum, Implementation
Solved
No attempts yet

Problem

MOLOCO is a company that matches advertisers with potential users through its high-performance ad platform.

Whenever an app has space available for an ad, the app asks the AdExchange platform to decide which ad to show. AdExchange then holds an auction, in which bidders such as MOLOCO bid for the chance to show their advertisement.

RUN wants to advertise its 2020 ICPC Mock Competition. They have asked MOLOCO to place the advertisement. RUN has a total of KK dollars and wants to display the ad in internal apps used by KAIST members. The ads in those apps are in one of six types, and the bidding price depends only on the type of ad. The first bidder to bid on the ad gets to show their ad.

AdExchange has already determined the costs of the six ad types and the NN auctions it will run today. In the ii-th auction, AdExchange runs an auction for an ad of type cic_i. AdExchange never runs two auctions at the same time; more specifically, auction i+1i+1 cannot start until after auction ii ends.

MOLOCO bids during auctions using the following strategy. Before the auctions begin, RUN selects a set of ad types. During the ii-th auction, if the ad type of that auction is in RUN's set and RUN has enough money to bid on an ad of that type, MOLOCO submits a bid. Otherwise, it ignores the auction.

MOLOCO is very fast at bidding, so it is always the first bidder if it bids on the ad. Find the maximum number of ads MOLOCO can bid on if RUN selects the set of ad types optimally.

Input

The first line contains two space-separated integers NN and KK. (1≤N≤100 000,0≤K≤1091 \le N \le 100\,000, 0 \le K \le 10^9)

The next line contains 6 integers b1,b2,…,b6b_1, b_2, \ldots, b_6. bib_i is the cost for ad type ii. (1≤bi≤1091 \le b_i \le 10^9)

The next line contains NN integers c1,c2,…,cNc_1, c_2, \ldots, c_N. cic_i is the ad type of the ii-th auction. (1≤ci≤61 \le c_i \le 6)

Output

Print the maximum number of ads MOLOCO can bid on.

Examples2

  1. Example 1

    Input
    6 10
    1 2 3 4 5 6
    6 5 4 3 2 1
    
    Expected output
    4
    
  2. Example 2

    Input
    12 10
    1 1 2 2 3 3
    6 5 4 3 2 1 1 2 3 4 5 6
    
    Expected output
    7