CF1165F2.Microtransactions (hard version)

普及+/提高

通过率:0%

时间限制:3.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≤2⋅1051 \le n, m \le 2 \cdot 10^5) — 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≤2⋅1050 \le k_i \le 2 \cdot 10^5), 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 2⋅1052 \cdot 10^5.

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≤2⋅105,1≤tj≤n1 \le d_j \le 2 \cdot 10^5, 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≤2⋅1051 \le n, m \le 2 \cdot 10^5),分别表示微交易类型的数量以及游戏商店中特价优惠的数量。

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

接下来的 mm 行描述特价优惠。其中第 jj 行描述第 jj 个特价优惠,以一对整数 (dj,tj)(d_j, t_j)(1≤dj≤2⋅105, 1≤tj≤n1 \le d_j \le 2 \cdot 10^5,\ 1 \le t_j \le n)给出,表示第 tjt_j 种微交易在第 djd_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测评打分。不知道怎么写?

首页