C. Petya and Exam
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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:
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 titi (0≤ti≤T0≤ti≤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≤sti≤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≤sti≤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=3t1=3 and the second problem is easy and t2=2t2=2. Then:
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.
Input
The first line contains the integer mm (1≤m≤1041≤m≤104) — 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≤n≤2⋅105, 1≤T≤1091≤T≤109, 1≤a
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 titi (0≤ti≤T0≤ti≤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⋅105.
Output
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.
Example
input
Copy
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
output
Copy
3 2 1 0 1 4 0 1 2 1
简单贪心 我们肯定是要贪心的先拿限制小的
然后再贪心的看是否能拿更多
#include
#define int long long
using namespace std;
struct node
{
int typ;
int t;
}pro[200005];
int cmp(node p,node q)
{
return p.t