题解
考虑从左到右第一个在游客范围里的公寓,显然把这个公寓分给范围里最左边的游客最优,因为右边的游客更高概率遇到公寓
code
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll inf=1e18;
const ll mod=1e9+7;
ll a[2000005],b[200005];
void solve()
{
ll n,m,k;
cin>>n>>m>>k;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
}
for(ll i=1;i<=m;i++)
{
cin>>b[i];
}
sort(a+1,a+1+n);
sort(b+1,b+1+m);
ll it1=1;
ll ans=0;
for(ll it2=1;it2<=m;it2++)
{
while(it1<=n&&a[it1]<b[it2]-k) it1++;
if(it1>n) break;
if(a[it1]>b[it2]+k) continue;
ans++;
it1++;
}
cout<<ans;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int TT=1;
//cin>>TT;
while(TT--) solve();
return 0;
}
标签:const,Apartments,ll,long,公寓,ans,it1
From: https://www.cnblogs.com/pure4knowledge/p/18333417