File tree 2 files changed +81
-0
lines changed
2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include " bits/stdc++.h"
2
+ using namespace std ;
3
+ #define ll long long int
4
+ #define endl " \n "
5
+
6
+ int main ()
7
+ {
8
+ ll i, n, m, k;
9
+ cin >> n >> m >> k;
10
+ ll a[n], b[m];
11
+
12
+ for (i = 0 ; i < n; i++)
13
+ {
14
+ cin >> a[i];
15
+ }
16
+
17
+ for (i = 0 ; i < m; i++)
18
+ {
19
+ cin >> b[i];
20
+ }
21
+
22
+ sort (a, a + n);
23
+ sort (b, b + m);
24
+
25
+ ll j = 0 , ans = 0 ;
26
+ i = 0 ;
27
+ while (i < n and j < m)
28
+ {
29
+ if (a[i] < b[j] - k)
30
+ {
31
+ i++;
32
+ }
33
+ else if (a[i] > b[j] + k)
34
+ {
35
+ j++;
36
+ }
37
+ else
38
+ {
39
+ i++;
40
+ j++;
41
+ ans++;
42
+ }
43
+ }
44
+
45
+ cout << ans << endl;
46
+
47
+ return 0 ;
48
+ }
Original file line number Diff line number Diff line change
1
+ #include " bits/stdc++.h"
2
+ #define ll long long int
3
+ #define endl " \n "
4
+ using namespace std ;
5
+
6
+ int main ()
7
+ {
8
+ ll n, m;
9
+ cin >> n >> m;
10
+ multiset<int , greater<int >> arr;
11
+ ll i, temp;
12
+ for (i = 0 ; i < n; i++)
13
+ {
14
+ cin >> temp;
15
+ arr.insert (temp);
16
+ }
17
+
18
+ for (i = 0 ; i < m; i++)
19
+ {
20
+ cin >> temp;
21
+ auto it = arr.lower_bound (temp);
22
+ if (it == arr.end ())
23
+ {
24
+ cout << " -1" << endl;
25
+ }
26
+ else
27
+ {
28
+ cout << *it << endl;
29
+ arr.erase (it);
30
+ }
31
+ }
32
+ return 0 ;
33
+ }
You can’t perform that action at this time.
0 commit comments