cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

commit cc8772b051522fc19f8c9f5370602b68b0b42b58
parent a0d2b24bbf50867a8c8946217dcfb8250fb16128
Author: superpozycja <anna@superpozycja.net>
Date:   Sun, 27 Oct 2024 14:28:06 +0100

solve apartments

Diffstat:
Asorting_and_searching/apartments.cpp | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+), 0 deletions(-)

diff --git a/sorting_and_searching/apartments.cpp b/sorting_and_searching/apartments.cpp @@ -0,0 +1,55 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + int n, m, k; + cin >> n >> m >> k; + int a[n]; + int b[m]; + for (int i = 0; i < n; i++) + cin >> a[i]; + + for (int i = 0; i < m; i++) + cin >> b[i]; + + sort(a, a+n); + sort(b, b+m); + + int res = 0; + int i = 0, j = 0; + while (i < n && j < m) { + if (a[i] < b[j] - k) { + i++; + } else if (a[i] > b[j] + k) { + j++; + } else { + i++; + j++; + res++; + } + } + + cout << res << "\n"; + + return; +} + +int main() +{ + solve(); +}