--- title: 3B 公寓出租 tags: solution --- # B. 公寓出租 - 本題源自於CSES:[Apartments](https://cses.fi/problemset/task/1084) ```cpp= # include <iostream> # include <algorithm> using namespace std; int a[200000], b[200000]; int main(){ int N,M,k,n,m,ans = 0; cin>>N>>M>>k; for(n = 0 ; n<N ; n++) cin>>a[n]; for(n = 0 ; n<M ; n++) cin>>b[n]; sort(a,a+N); sort(b,b+M); n = m = 0; while(n<N && m<M){ if(abs(a[n]-b[m])<=k) ans++, m++, n++; else if(b[m] < a[n]) m++; else n++; } cout<<ans; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up