-
Notifications
You must be signed in to change notification settings - Fork 0
/
Apple_and_Orange.cpp
48 lines (46 loc) · 1.31 KB
/
Apple_and_Orange.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Title : Apple_and_Orange.cpp
* Author : Tridib Samanta
* Created : 30-12-2019
* Link : https://www.hackerrank.com/challenges/apple-and-orange/problem
**/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int s,t;
//Take input the starting and ending position of the house
scanf("%d%d",&s,&t);
int a,b;
//Take input the position of apple tree and orange tree
scanf("%d%d",&a,&b);
int m,n;
//Take input the number of apples and oranges
scanf("%d%d",&m,&n);
int apple_count=0,orange_count=0;
//The number of apples that fall on Sam's House
for(int i=0;i<m;i++) {
int apple_dist=0,landing_pos=0;
scanf("%d",&apple_dist);
landing_pos=a+apple_dist;
if(landing_pos>=s && landing_pos<=t)
apple_count++;
}
//The number of oranges that fall on Sam's House
for(int i=0;i<n;i++) {
int orange_dist=0,landing_pos=0;
scanf("%d",&orange_dist);
landing_pos=b+orange_dist;
if(landing_pos>=s && landing_pos<=t)
orange_count++;
}
printf("%d\n%d\n",apple_count,orange_count);
return 0;
}