-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path4.c
111 lines (61 loc) · 2.39 KB
/
4.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Given two arrays of positive integers, for each element in the second array, find the total number of elements in the first array
// which are less than or equal to that element. Store the values determined in an array.
// For example, if the first array is [1, 2, 3] and the second array is [2, 4], then there are 2 elements in the first array less than or equal to 2.
// There are 3 elements in the first array which are less than or equal to 4. We can store these answers in an array, answer = [2, 3].
// Program Description
// The program must return an array of m positive integers, one for each maxes[i] representing the total number of
// elements nums[j] satisfying nums[j] ≤ maxes[i] where 0 ≤ j < n and 0 ≤ i < m, in the given order.
// The program has the following:
// nums[nums[0],...nums[n-1]]: first array of positive integers
// maxes[maxes[0],...maxes[n-1]]: second array of positive integers
// Constraints
// · 2 ≤ n, m ≤ 105
// · 1 ≤ nums[j] ≤ 109, where 0 ≤ j < n.
// · 1 ≤ maxes[i] ≤ 109, where 0 ≤ i < m.
// Input Format For Custom Testing
// Input from stdin will be processed as follows and passed to the program.
// The first line contains an integer n, the number of elements in nums.
// The next n lines each contain an integer describing nums[j] where 0 ≤ j < n.
// The next line contains an integer m, the number of elements in maxes.
// The next m lines each contain an integer describing maxes[i] where 0 ≤ i < m.
// Sample Case 0
// Sample Input 0
// 4
// 1
// 4
// 2
// 4
// 2
// 3
// 5
// Sample Output 0
// 2
// 4
// Explanation 0
// We are given n = 4, nums = [1, 4, 2, 4], m = 2, and maxes = [3, 5].
// 1. For maxes[0] = 3, we have 2 elements in nums (nums[0] = 1 and nums[2] = 2) that are ≤ maxes[0].
// 2. For maxes[1] = 5, we have 4 elements in nums (nums[0] = 1, nums[1] = 4, nums[2] = 2, and nums[3] = 4) that are ≤ maxes[1].
// Thus, the program returns the array [2, 4] as the answer.
#include<stdio.h>
int main()
{
int n,m;
scanf("%d",&n);
int a1[n];
for(int i=0;i<n;i++)
scanf("%d",&a1[i]);
scanf("%d",&m);
int a2[m];
for(int i=0;i<m;i++)
scanf("%d",&a2[i]);
for(int i=0;i<m;i++)
{
int c=0;
for(int j=0;j<n;j++)
{
if(a2[i]>=a1[j])
c++;
}
printf("%d\n",c);
}
}