CF1165F1.Microtransactions (easy version)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The only difference between easy and hard versions is constraints.

Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions — and he won't start playing until he gets all of them.

Each day (during the morning) Ivan earns exactly one burle.

There are nn types of microtransactions in the game. Each microtransaction costs 22 burles usually and 11 burle if it is on sale. Ivan has to order exactly kik_i microtransactions of the ii-th type (he orders microtransactions during the evening).

Ivan can order any (possibly zero) number of microtransactions of any types during any day (of course, if he has enough money to do it). If the microtransaction he wants to order is on sale then he can buy it for 11 burle and otherwise he can buy it for 22 burles.

There are also mm special offers in the game shop. The jj-th offer (dj,tj)(d_j, t_j) means that microtransactions of the tjt_j-th type are on sale during the djd_j-th day.

Ivan wants to order all microtransactions as soon as possible. Your task is to calculate the minimum day when he can buy all microtransactions he want and actually start playing.

简单版本与困难版本的唯一区别在于约束条件。

伊万正在玩一款电脑游戏,游戏中包含一些微交易,用于让角色外观更炫酷。由于伊万希望自己的角色真正酷炫,他打算购买其中若干微交易——并且他不会开始玩游戏,直到他获得全部所需的微交易为止。

每天(清晨),伊万恰好赚取 1 卢布(burle)。

游戏中共有 nn 种微交易。通常情况下,每种微交易价格为 2 卢布;若该微交易处于促销状态,则仅需 1 卢布。伊万需要恰好购买第 ii 种微交易 kik_i 个(他在每天傍晚下单)。

在任意一天(当然前提是他拥有足够资金),伊万可以购买任意数量(包括零个)的任意种类微交易。若他想购买的微交易正处于促销状态,则只需花费 1 卢布;否则需花费 2 卢布。

此外,游戏商店还提供 mm 个特别优惠。第 jj 个优惠 (dj,tj)(d_j, t_j) 表示:在第 djd_j 天,第 tjt_j 种微交易处于促销状态。

伊万希望尽快完成所有微交易的购买。你的任务是计算出他能够买齐所有所需微交易并真正开始游戏的最早天数。

输入格式

The first line of the input contains two integers nn and mm (1≤n,m≤10001 \le n, m \le 1000) — the number of types of microtransactions and the number of special offers in the game shop.

The second line of the input contains nn integers k1,k2,…,knk_1, k_2, \dots, k_n (0≤ki≤10000 \le k_i \le 1000), where kik_i is the number of copies of microtransaction of the ii-th type Ivan has to order. It is guaranteed that sum of all kik_i is not less than 11 and not greater than 10001000.

The next mm lines contain special offers. The jj-th of these lines contains the jj-th special offer. It is given as a pair of integers (dj,tj)(d_j, t_j) (1≤dj≤1000,1≤tj≤n1 \le d_j \le 1000, 1 \le t_j \le n) and means that microtransactions of the tjt_j-th type are on sale during the djd_j-th day.

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤10001 \le n, m \le 1000)——分别表示微交易类型的数量以及游戏商店中特价优惠的数量。

输入的第二行包含 nn 个整数 k1,k2,…,knk_1, k_2, \dots, k_n(0≤ki≤10000 \le k_i \le 1000),其中 kik_i 表示 Ivan 需要订购的第 ii 种微交易的份数。保证所有 kik_i 的总和不小于 11 且不大于 10001000。

接下来的 mm 行描述特价优惠。其中第 jj 行描述第 jj 个特价优惠,以一对整数 (dj,tj)(d_j, t_j)(1≤dj≤1000, 1≤tj≤n1 \le d_j \le 1000,\ 1 \le t_j \le n)给出,表示在第 djd_j 天,第 tjt_j 种微交易正在促销。

输出格式

Print one integer — the minimum day when Ivan can order all microtransactions he wants and actually start playing.

输出一个整数——伊万能够订购所有他想要的微交易并真正开始游戏的最早天数。

输入输出样例

  • 输入#1

    5 6
    1 2 0 2 0
    2 4
    3 3
    1 5
    1 2
    1 5
    2 3

    输出#1

    8
  • 输入#2

    5 3
    4 2 1 3 2
    3 5
    4 2
    2 5

    输出#2

    20

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

首页