/*
APPLE AND ORANGE
Sam's house has an apple tree and an orange tree that yield an abundance of fruit. In the diagram below, the red region denotes his house, where s is the start point and t is the end point. The apple tree is to the left of his house, and the orange tree is to its right. You can assume the trees are located on a single point, where the apple tree is at point a and the orange tree is at point b.
Apple and orange(2).png
When a fruit falls from its tree, it lands d units of distance from its tree of origin along the x-axis. A negative value of d means the fruit fell d units to the tree's left, and a positive value of d means it falls d units to the tree's right.
Given the value of d for m apples and n oranges, can you determine how many apples and oranges will fall on Sam's house (i.e., in the inclusive range [s,t])? Print the number of apples that fall on Sam's house as your first line of output, then print the number of oranges that fall on Sam's house as your second line of output.
Input Format
The first line contains two space-separated integers denoting the respective values of s and t.
The second line contains two space-separated integers denoting the respective values of a and b.
The third line contains two space-separated integers denoting the respective values of m and n.
The fourth line contains m space-separated integers denoting the respective distances that each apple falls from point a.
The fifth line contains n space-separated integers denoting the respective distances that each orange falls from point b.
Constraints
* 1 <= s, t, a, b, m, n <= 10^5
* -10^5 <= d <= 10^5
* a < s < t < b
Output Format
Print two lines of output:
1 On the first line, print the number of apples that fall on Sam's house.
2 On the second line, print the number of oranges that fall on Sam's house.
Sample Input 0
7 11
5 15
3 2
-2 2 1
5 -6
Sample Output 0
1
1
Explanation 0
The first apple falls at position 5 - 2 = 3.
The second apple falls at position 5 + 2 = 7.
The third apple falls at position 5 + 1 = 8.
The first orange falls at position 15 + 5 = 20.
The second orange falls at position 15 - 6 = 11.
Only one fruit (the second apple) falls within the region between 7 and 11, so we print 1 as our first line of output.
Only the second orange falls within the region between 7 and 11, so we print 1 as our second line of output.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
public static class House{
// Static Constructor
static House(){ // Initializes variables and create instances of Tree.
Start = 0; // Initial value of Start
End = 0; // Initial value of End
AQueries = 0; // Initial value of Apple queries
OQueries = 0; // Initial value of Orange queries
Apple = new Tree(); // Creating an instance of the Apple Tree.
Orange = new Tree(); // Creating an instance of the Orange Tree.
}
// Properties
public static int Start{ get; set; } // Starting position of the house.
public static int End{ get; set; } // Ending position of the house.
public static int AQueries { get; set; } // Number of Apple queries
public static int OQueries { get; set; } // Number of Orange queries
public static Tree Apple { get; set; } // Apple Tree
public static Tree Orange { get; set; } // Orange Tree
// Method
public static void display(){ // Calls the display methods for each Tree.
Apple.display(Start, End);
Orange.display(Start, End);
}
}
public class Tree{
// Private variable
private List<int> _lintFruit; // Contains the positions of each fruit.
// Constructor
public Tree(){
X = 0; // Starting position of the Tree.
_lintFruit = new List<int>(); // Initializes the list.
}
// Property
public int X{ get; set; } // Position of the Tree.
// Methods
public void setFruit(int[] value) { // Takes the int array and stores it in a list.
foreach(int val in value){
_lintFruit.Add(val + X); // Adds the Tree's position to the value to find the fruit's position.
}
}
public void display(int start, int end){
Console.WriteLine("{0}", _lintFruit.Where(y => y >= start && y <= end).Count()); // Prints the number of fruit that is within the range.
}
}
static void Main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
IInput input;
if (args.Length > 0){
input = new StringInput(System.IO.File.ReadAllLines(args[0]));
} else {
input = new ConsoleInput();
}
int[] values = input.ReadIntArray();
House.Start = values[0];
House.End = values[1];
values = input.ReadIntArray();
House.Apple.X = values[0];
House.Orange.X = values[1];
values = input.ReadIntArray();
House.AQueries = values[0];
House.OQueries = values[1];
House.Apple.setFruit(input.ReadIntArray());
House.Orange.setFruit(input.ReadIntArray());
House.display();
}
public interface IInput{
string ReadLine();
int ReadInt();
int[] ReadIntArray();
}
public class ConsoleInput : IInput{
public string ReadLine(){
return Console.ReadLine().Trim();
}
public int ReadInt(){
return Convert.ToInt32(ReadLine());
}
public int[] ReadIntArray(){
return Array.ConvertAll(ReadLine().Split(' '), Int32.Parse);
}
}
public class StringInput : IInput{
IEnumerable<string> _data;
IEnumerator<string> _dataEnumerator;
public StringInput (IEnumerable<string> data){
_data = data;
_dataEnumerator = _data.GetEnumerator();
}
public string ReadLine(){
_dataEnumerator.MoveNext();
string retVal = _dataEnumerator.Current.Trim();
return retVal;
}
public int ReadInt(){
return Convert.ToInt32(ReadLine());
}
public int[] ReadIntArray(){
return Array.ConvertAll(ReadLine().Split(' '), Int32.Parse);
}
}
}