Shivam , Shantam and their Absolute Difference
Practice
3.7 (866 votes)
Medium
Problem
24% Success 4103 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

"Sometimes the thing that brings us together also pulls us apart." - Jarod Kintz.

Shivam and Shantam are really good friends. What mostly brings them together is the hours of group study they have done in the two years of their engineering, and there is only more to add to this. They both start studying together for exams , and keep explaining topics and clearing each other's slightest of doubts.

But , unfortunately , marks and money can always make or break relations. Both of them have to answer N questions in tomorrow's paper. We also have two arrays , A and B. Ai denotes the marks Shivam will get if he answers the ith question. Bi denotes the marks Shantam will get if he answers the ith question. The person not choosing to answer the question would get no marks.

Obviously , there are many ways in which they can give their papers. Let the final score of Shivam be S and that of Shantam be K. We are interested in knowing the number of ways such that the absolute difference in S and K is less than or equal to Q.

Input Format :

The first line contains N , the number of questions. The next line contains N space separated integers denoting Ai , the marks that Shivam can score if he attempts the ith question. The next line contains N space separated integers denoting Bi , the marks that Shantam can score if he attempts the ith question. The next line contains Q , the maximum allowed absolute difference.

Output Format :

Since the number of ways can be huge , output the answer modulo 109 + 7 in a separate line.

Contraints :

  • 1 ≤ N ≤ 200
  • 0 ≤ Ai, Bi ≤ 2 * 103
  • 0 ≤ Q ≤ 10^6

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
4 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpen
Points:30
4 votes
Tags:
DatastructuresAlgorithmsDynamic ProgrammingIntroduction to Dynamic Programming 1Bitmask
Points:30
1 votes
Tags:
Max subarray sumIntroduction to Dynamic Programming 1Dynamic ProgrammingAlgorithms