-
Notifications
You must be signed in to change notification settings - Fork 0
/
Apartments.cpp
204 lines (166 loc) · 5.64 KB
/
Apartments.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/// say Alhamdulillah
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0);
// cout.tie(0);
#define ll long long
// #define init \
// ll count = 0, zz, t; \
// cin >> t; \
// while (t--)
#define ld long double
#define ed "\n"
#define eb emplace_back
#define con continue
#define bre break
#define pl " "
#define pll " --- "
// #define size size()
#define mpr make_pair
#define vec vector<ll>
#define lmax LONG_LONG_MAX
#define lmin LONG_LONG_MIN
#define forr(i, a, b) for (ll i = a; i < b; i++)
#define forrev(i, a, b) for (ll i = a; i >= b; i--)
// #define v.all v.begin(), v.end()
#define printArrWhole(arr, n) \
for (ll i = 0; i < n; i++) \
cout << arr[i] << " "; \
cout << endl;
#define printArrLim(arr, in, n) \
for (ll i = in; i <= n; i++) \
cout << arr[i] << " "; \
cout << endl;
#define printYesNo(flag) \
if (flag == 0) \
cout << "NO"; \
else \
cout << "YES"; \
cout << endl;
#define printvcWhole(vc) \
for (auto x : vc) \
cout << x << " "; \
cout << endl;
#define printvcLim(vc, in, n) \
for (ll i = in; i <= n; i++) \
cout << vc[i] << " "; \
cout << endl;
#define printdqWhole(dq) \
for (auto x : dq) \
cout << x << " "; \
cout << endl;
#define printdqLim(dq, in, n) \
for (ll i = in; i <= n; i++) \
cout << dq[i] << " "; \
cout << endl;
#define sortArr(arr, n) sort(arr, arr + n);
#define sortvc(v) sort(v.begin(), v.end());
#define rev(v) reverse(v.begin(), v.end());
// #define find(v, x) find(v.begin(), v.end(), x);
ll maxDigit(ll n) {
ll maxi = 0;
while (n > 0) {
maxi = max(maxi, n % 10);
n /= 10;
}
return maxi;
}
int main() {
fast
// init
{
// count++;
ll i, j, k, x, y, z, p, q, m, n, l, r, l1, l2, r1, r2, ans, pos, flag, sum;
ll mini = lmax, maxi = -1, piv, low, high, rem, prev, now, mid, bit;
ll dif = 0, change = 0, total = 0, same = 0, plus = 0, minus = 0, zero = 0;
cin >> n >> m >> k;
// cout<<piv;
// char ch, ch1, ch2, ch3, ch4;
// string sarr[n];
// string s, s1 = "", s2 = "";
// string res1 = "", res2 = "", chk1 = "", chk2 = "", chk3 = "", chk4 = "",
// pivs = "", rems = "";
// n = s.size;
// ll arr[n+1];
// number[n], cost[n], forsum[n+1], backsum[n];
vector<ll> v, v1, v2, vans, vpos, vlen, vsum, vdif;
// vector <string> vstr(n);
// vector<pair<ll, ll>> vpr;
// vector<vec> vdarr(n, vec(10, 0));
// deque<ll> dq, dq1, dq2;
// pair<ll, ll> pr, pr1, pr2,pr3, pr4;
// set <ll> st, st1, st2, ms, ldiff, rdiff;
multiset<ll> mst, mst1, mst2;
// multiset<ll, greater<ll>> mst, mst1, mst2;
// priority_queue<ll> pq, pq1, pq2;
// stack<ll> stck, stck1, stck2;
// map<ll, ll> mp, mp1, mp2;
// map<pair<ll,ll>,ll> mpair, mpair1, mpair2;
// vector<pair<ll,ll>> vpr, vpr1, vpr2;
// queue<ll> vq[10],vq1,vq2;
// multiset<ll>::iterator itr, itr1, itr2;
// Point pa,pb,pc,pd;//,pt[1001];
// Node pa,pb,pt[n];
// cout<<"-----------------yess"<<endl;
ans = 0;
prev = -1;
// piv=0;
// flag=0;
// sum=0;
// bit=1;
forr(i, 0, n) {
cin >> x;
v1.eb(x);
}
forr(i, 0, m) {
cin >> x;
mst2.insert(x);
}
sortvc(v1);
// sortvc(v2);
// printvcWhole(v1);
// printvcWhole(mst2);
////////////////////////////////////////////////////////
forr(i, 0, n) {
piv = v1[i] - k;
auto it = mst2.lower_bound(piv);
if (it == mst2.end())
continue;
if (abs(piv - *it) <= 2 * k) {
ans++;
mst2.erase(it);
}
}
cout << ans << ed;
////////////////////////////////////////////////////////
// i=0;
// j=0;
// while(i<n && j<m)
// {
// // cout<<i<<pll<<j<<pll;
// if(v1[i]-k <= v2[j] && v2[j] <= v1[i]+k)
// {
// ans++;
// i++;
// j++;
// // cout<<"1st\n";
// }
// else if(v2[j] < v1[i]-k)
// {
// // while(j<m && v2[j] < v1[i]-k)
// j++;
// // cout<<"2nd\n";
// }
// else
// if(v2[j] > v1[i]+k)
// {
// // while(i<n && v2[j] > v1[i]+k)
// i++;
// // cout<<"3rd\n";
// }
// }
// cout<<ans<<endl;
}
}