题解
简单的二分应用,对于每个bi我们只需找到最大的ci使得bi+ci<=target即可
code
#include<bits/stdc++.h> using namespace std; int a[105],b[105]; int main(){ // freopen("input.txt","r",stdin); int t; cin>>t; while (t--){ int n,m,k,sum=0; cin>>n>>m>>k; for (int i=1;i<=n;i++) cin>>a[i]; for (int i=1;i<=m;i++) cin>>b[i]; sort(a+1,a+n+1); sort(b+1,b+m+1); for (int i=1;i<=n;i++){ if (a[i]+b[1]>k) break; int l=1,r=m+1; while (l+1<r){ int mid=l+(r-l>>1); if (a[i]+b[mid]<=k) l=mid; else r=mid; } sum+=l; } cout<<sum<<endl; } return 0; }
标签:sort,ci,int,bi,Ticket,Rudolf From: https://www.cnblogs.com/purple123/p/18077211