CF309C.Memory for Arrays

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You get to work and turn on the computer. You start coding and give little thought to the RAM role in the whole process. In this problem your task is to solve one of the problems you encounter in your computer routine.

We'll consider the RAM as a sequence of cells that can contain data. Some cells already contain some data, some are empty. The empty cells form the so-called memory clusters. Thus, a memory cluster is a sequence of some consecutive empty memory cells.

You have exactly n memory clusters, the i-th cluster consists of a__i cells. You need to find memory for m arrays in your program. The j-th array takes 2_b__j_ consecutive memory cells. There possibly isn't enough memory for all m arrays, so your task is to determine what maximum number of arrays can be located in the available memory clusters. Of course, the arrays cannot be divided between the memory clusters. Also, no cell can belong to two arrays.

你来到公司开始工作,打开电脑,随即开始编写代码,却很少思考 RAM 在整个过程中的作用。在本题中,你的任务是解决你在日常使用电脑时遇到的一个问题。

我们将 RAM 视为一个可存储数据的单元序列。其中某些单元已存有数据,另一些则为空。这些空单元构成所谓的“内存簇”。因此,一个内存簇即一段连续的空内存单元。

你恰好拥有 nn 个内存簇,其中第 ii 个簇包含 aia_i 个单元。你的程序需要为 mm 个数组分配内存。第 jj 个数组需占用 2bj2^{b_j} 个连续的内存单元。由于可用内存可能不足以容纳全部 mm 个数组,你的任务是确定:在给定的内存簇中,最多能成功存放多少个数组。当然,每个数组必须完全存放在某一个内存簇内(不可跨簇存放),且任意内存单元至多属于一个数组。

输入格式

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 106). The next line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109). The next line contains m integers _b_1, b_2, ..., b__m (1 ≤ 2_b__i ≤ 109).

输入的第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 1061 \leq n, m \leq 10^6)。
第二行包含 nn 个整数 a1, a2, ..., ana_1, a_2, ..., a_n(1 ≤ ai ≤ 1091 \leq a_i \leq 10^9)。
第三行包含 mm 个整数 b1, b2, ..., bmb_1, b_2, ..., b_m(1 ≤ bi ≤ 1091 \leq b_i \leq 10^9)。

输出格式

Print a single integer — the answer to the problem.

输出一个整数——该问题的答案。

输入输出样例

  • 输入#1

    5 3
    8 4 3 2 2
    3 2 2

    输出#1

    2
  • 输入#2

    10 6
    1 1 1 1 1 1 1 1 1 1
    0 0 0 0 0 0

    输出#2

    6

说明/提示

In the first example you are given memory clusters with sizes 8, 4, 3, 2, 2 and arrays with sizes 8, 4, 4. There are few ways to obtain an answer equals 2: you can locate array with size 8 to the cluster with size 8, and one of the arrays with size 4 to the cluster with size 4. Another way is to locate two arrays with size 4 to the one cluster with size 8.

In the second example you are given 10 memory clusters with size 1 and 6 arrays with size 1. You can choose any 6 clusters and locate all given arrays to them.

在第一个例子中,给定内存簇的大小为 8、4、3、2、2,数组的大小为 8、4、4。存在若干种方式使得答案等于 2:你可以将大小为 8 的数组分配到大小为 8 的内存簇中,并将其中一个大小为 4 的数组分配到大小为 4 的内存簇中;另一种方式是将两个大小为 4 的数组都分配到唯一一个大小为 8 的内存簇中。

在第二个例子中,给定 10 个大小为 1 的内存簇和 6 个大小为 1 的数组。你可以任选其中 6 个内存簇,并将所有给定的数组分配到这些簇中。

输入解题思路,AI测评打分。不知道怎么写?

首页