Rohit and his brother
Practice
2.9 (10 votes)
Algorithms
Dynamic programming
Introduction to dynamic programming 1
Problem
42% Success 1278 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Rohit and his brother Rohan have two old wooden chests, \(A\) and \(B\), consisting of \(N\) integers. They also got an old rusted trunk with lots of diamonds inside it. However, the rusted trunk has a lock that can only be opened if they know the number of combinations possible such that the following conditions are satisfied. 

Assume they choose a set of numbers {\({S_1,S_2,S_3...S_K}\)} consisting of integers from \(1\) to \(N\). Let \(A_{max}\) denote the maximum element of the numbers, {\( A[S_1], A[S_2]...A[S_K]\)} and \(B_{sum}\) denote the sum of the elements {\(B[S_1], B[S_2]...B[S_K]\)}. Then, \(A_{max}\) must be greater than or equal to \(B_{sum}\). Since the answer could be large, compute it modulo \(10^9+7\).

Input Format :

  • The first line contains a single integer \(T\) representing the number of test cases. Then each test case follows.
  • The first line of each test case contains an integer \(N\) denoting the number of integers in the wooden trunks \(A\) and \(B\).
  • The second line of every test case contains \(N\) integers denoting the integers contained in the wooden chest \(A\).
  • The third line of every test case contains \(N\) integers denoting the integers contained in the wooden chest \(B\).

Output Format :
For each test case, print an integer denoting the number of subsets or combinations satisfying the conditions given in the statement modulo \(10^9+7\).

Constraints :
\(1 \leq T \leq 5\)
\(1 \leq N \leq 1000\)
\(1 \leq A_i \leq 1000\)
\(1 \leq B_i \leq 1000\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
Introduction to Dynamic Programming 1AlgorithmsDynamic ProgrammingBinary Search
Points:30
866 votes
Tags:
Medium
Points:30
4 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpen