CF1282C.Petya and Exam

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes.

The exam consists of nn problems that can be solved in TT minutes. Thus, the exam begins at time 00 and ends at time TT. Petya can leave the exam at any integer time from 00 to TT, inclusive.

All problems are divided into two types:

  • easy problems — Petya takes exactly aa minutes to solve any easy problem;
  • hard problems — Petya takes exactly bb minutes (b>ab \gt a) to solve any hard problem.

Thus, if Petya starts solving an easy problem at time xx, then it will be solved at time x+ax+a. Similarly, if at a time xx Petya starts to solve a hard problem, then it will be solved at time x+bx+b.

For every problem, Petya knows if it is easy or hard. Also, for each problem is determined time tit_i (0≤ti≤T0 \le t_i \le T) at which it will become mandatory (required). If Petya leaves the exam at time ss and there is such a problem ii that ti≤st_i \le s and he didn't solve it, then he will receive 00 points for the whole exam. Otherwise (i.e if he has solved all such problems for which ti≤st_i \le s) he will receive a number of points equal to the number of solved problems. Note that leaving at time ss Petya can have both "mandatory" and "non-mandatory" problems solved.

For example, if n=2n=2, T=5T=5, a=2a=2, b=3b=3, the first problem is hard and t1=3t_1=3 and the second problem is easy and t2=2t_2=2. Then:

  • if he leaves at time s=0s=0, then he will receive 00 points since he will not have time to solve any problems;
  • if he leaves at time s=1s=1, he will receive 00 points since he will not have time to solve any problems;
  • if he leaves at time s=2s=2, then he can get a 11 point by solving the problem with the number 22 (it must be solved in the range from 00 to 22);
  • if he leaves at time s=3s=3, then he will receive 00 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
  • if he leaves at time s=4s=4, then he will receive 00 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
  • if he leaves at time s=5s=5, then he can get 22 points by solving all problems.

Thus, the answer to this test is 22.

Help Petya to determine the maximal number of points that he can receive, before leaving the exam.

佩佳参加了数学考试,希望尽可能多地解出题目。他做了充分准备,并仔细研究了考试的规则。

考试共有 nn 道题目,总时长为 TT 分钟。考试从时刻 00 开始,到时刻 TT 结束。佩佳可以在任意整数时刻 ss(0≤s≤T0 \le s \le T)离开考场。

所有题目分为两类:

  • 简单题——佩佳解任意一道简单题恰好需要 aa 分钟;
  • 困难题——佩佳解任意一道困难题恰好需要 bb 分钟(b>ab > a)。

因此,若佩佳在时刻 xx 开始解一道简单题,则该题将在时刻 x+ax+a 解出;类似地,若他在时刻 xx 开始解一道困难题,则该题将在时刻 x+bx+b 解出。

对于每道题,佩佳都知道它是简单题还是困难题。此外,每道题还指定一个时间 tit_i(0≤ti≤T0 \le t_i \le T),表示该题在时刻 tit_i 起变为必答题(即强制要求)。若佩佳在时刻 ss 离开考场,且存在某道题 ii 满足 ti≤st_i \le s 但佩佳并未解出它,则他本次考试得分为 00。否则(即他对所有满足 ti≤st_i \le s 的题目均已完成求解),他的得分等于其已解出的题目总数。注意:当佩佳在时刻 ss 离开时,他可能既解出了“必答题”,也解出了“非必答题”。

例如,若 n=2n=2,T=5T=5,a=2a=2,b=3b=3,第一题为困难题且 t1=3t_1=3,第二题为简单题且 t2=2t_2=2。则:

  • 若他在时刻 s=0s=0 离开,则得分为 00,因为他没有时间解出任何题目;
  • 若他在时刻 s=1s=1 离开,则得分为 00,因为他没有时间解出任何题目;
  • 若他在时刻 s=2s=2 离开,则他可通过解出第 22 题获得 11 分(该题必须在 [0,2][0, 2] 时间段内完成);
  • 若他在时刻 s=3s=3 离开,则得分为 00,因为此时两道题均为必答题,但他无法在 33 分钟内全部解出;
  • 若他在时刻 s=4s=4 离开,则得分为 00,因为此时两道题均为必答题,但他仍无法在 44 分钟内全部解出;
  • 若他在时刻 s=5s=5 离开,则他可通过解出全部两道题获得 22 分。

因此,本测试用例的答案为 22。

请帮助佩佳确定他在离开考试前所能获得的最高得分。

输入格式

The first line contains the integer mm (1≤m≤1041 \le m \le 10^4) — the number of test cases in the test.

The next lines contain a description of mm test cases.

The first line of each test case contains four integers n,T,a,bn, T, a, b (2≤n≤2⋅1052 \le n \le 2\cdot10^5, 1≤T≤1091 \le T \le 10^9, 1≤a<b≤1091 \le a \lt b \le 10^9) — the number of problems, minutes given for the exam and the time to solve an easy and hard problem, respectively.

The second line of each test case contains nn numbers 00 or 11, separated by single space: the ii-th number means the type of the ii-th problem. A value of 00 means that the problem is easy, and a value of 11 that the problem is hard.

The third line of each test case contains nn integers tit_i (0≤ti≤T0 \le t_i \le T), where the ii-th number means the time at which the ii-th problem will become mandatory.

It is guaranteed that the sum of nn for all test cases does not exceed 2⋅1052\cdot10^5.

第一行包含一个整数 mm(1≤m≤1041 \le m \le 10^4)—— 表示测试用例的数量。

接下来的若干行描述了 mm 个测试用例。

每个测试用例的第一行包含四个整数 n,T,a,bn, T, a, b(2≤n≤2⋅1052 \le n \le 2\cdot10^5,1≤T≤1091 \le T \le 10^9,1≤a<b≤1091 \le a \lt b \le 10^9)—— 分别表示题目数量、考试总时长(单位:分钟)、解决一道简单题和一道难题所需的时间。

每个测试用例的第二行包含 nn 个数字(00 或 11),以单个空格分隔:第 ii 个数字表示第 ii 道题的类型。值为 00 表示该题为简单题,值为 11 表示该题为难题。

每个测试用例的第三行包含 nn 个整数 tit_i(0≤ti≤T0 \le t_i \le T),其中第 ii 个数表示第 ii 道题变为必答题的时间点。

保证所有测试用例的 nn 值之和不超过 2⋅1052\cdot10^5。

输出格式

Print the answers to mm test cases. For each set, print a single integer — maximal number of points that he can receive, before leaving the exam.

输出 mm 个测试用例的答案。对于每组数据,输出一个整数——他在离开考试前能够获得的最高分数。

输入输出样例

  • 输入#1

    10
    3 5 1 3
    0 0 1
    2 1 4
    2 5 2 3
    1 0
    3 2
    1 20 2 4
    0
    16
    6 20 2 5
    1 1 0 1 0 0
    0 8 2 9 11 6
    4 16 3 6
    1 0 1 1
    8 3 5 6
    6 20 3 6
    0 1 0 0 1 0
    20 11 3 20 16 17
    7 17 1 6
    1 1 0 1 0 0 0
    1 7 0 11 10 15 10
    6 17 2 6
    0 0 1 0 0 1
    7 6 3 7 10 12
    5 17 2 5
    1 1 1 1 0
    17 11 10 6 4
    1 1 1 2
    0
    1

    输出#1

    3
    2
    1
    0
    1
    4
    0
    1
    2
    1

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

首页