some dp problems
This commit is contained in:
36
CSES - CSES Problem Set/Sorting_And_Searching/Apartments.cpp
Normal file
36
CSES - CSES Problem Set/Sorting_And_Searching/Apartments.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Apartments
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
using ll = long long;
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
ll k; cin >> n >> m >> k;
|
||||
vector<ll> as(n);
|
||||
for (auto &e: as) cin >> e;
|
||||
vector<ll> bs(m);
|
||||
for (auto &e: bs) cin >> e;
|
||||
std::sort(as.begin(), as.end(), greater<ll>());
|
||||
std::sort(bs.begin(), bs.end(), greater<ll>());
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (as.size()) {
|
||||
int val = as.back();
|
||||
as.pop_back();
|
||||
while (bs.size()) {
|
||||
int val2 = bs.back();
|
||||
if (val2 > val + k) break;
|
||||
bs.pop_back();
|
||||
if (val2 + k >= val && val2 - k <= val) {
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user