CF799D.Field expansion

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Arkady's choice) by a__i. Each extension can't be used more than once, the extensions can be used in any order.

Now Arkady's field has size h × w. He wants to enlarge it so that it is possible to place a rectangle of size a × b on it (along the width or along the length, with sides parallel to the field sides). Find the minimum number of extensions needed to reach Arkady's goal.

在 Arkady 喜爱的某款游戏中,游戏过程发生在一个矩形场地上。在游戏中,Arkady 可以为他的场地购买扩展模块,每个扩展模块会将其场地的某一边(宽或长)按特定倍数放大。形式化地说,共有 nn 个扩展模块,其中第 ii 个模块可由 Arkady 自主选择,将场地的宽或长乘以 aia_i。每个扩展模块最多只能使用一次,且扩展模块可以按任意顺序使用。

目前 Arkady 的场地尺寸为 h×wh \times w。他希望扩大场地,使得一个尺寸为 a×ba \times b 的矩形能够被完整放置于其上(可沿宽度方向或长度方向放置,且矩形边须与场地边平行)。求达成 Arkady 目标所需的最少扩展模块数量。

输入格式

The first line contains five integers a, b, h, w and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions.

The second line contains n integers _a_1, _a_2, ..., a__n (2 ≤ a__i ≤ 100 000), where a__i equals the integer a side multiplies by when the i-th extension is applied.

第一行包含五个整数 aa、bb、hh、ww 和 nn(1 ≤ a, b, h, w, n ≤ 100 0001 ≤ a, b, h, w, n ≤ 100\,000)——分别表示待放置矩形的尺寸、场地的初始尺寸以及可用扩展的数量。

第二行包含 nn 个整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(2 ≤ ai ≤ 100 0002 ≤ a_i ≤ 100\,000),其中 aia_i 表示应用第 ii 个扩展时某一边长所乘的整数因子。

输出格式

Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.

输出达到阿尔卡季目标所需的最少扩展次数。如果在所有扩展后仍无法将矩形放置在场地上,则输出 -1。如果矩形可以直接放置在初始场地上,则输出 0。

输入输出样例

  • 输入#1

    3 3 2 4 4
    2 5 4 10

    输出#1

    1
  • 输入#2

    3 3 3 3 5
    2 3 5 4 2

    输出#2

    0
  • 输入#3

    5 5 1 2 3
    2 2 3

    输出#3

    -1
  • 输入#4

    3 4 1 1 3
    2 3 2

    输出#4

    3

说明/提示

In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.

在第一个例子中,使用任意一种可用的扩展方式即可。例如,我们可以使用第二种扩展方式将 hh 放大 5 倍。此时 hh 变为 10,从而可以在棋盘上放置该矩形。

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

首页