链接:https://www.nowcoder.com/acm/contest/126/A
来源:牛客网
齐国的大将田忌很喜欢赛马,有一回他被齐威王请来赛 k 天马。经过精心的准备,现在田忌有 n 匹速度分别为 a1, a2, …, an 的马,齐威王则有 n 匹速度分别为 b1, b2, …, bn 的马。每天要进行 n 场比赛,每场比赛田忌和齐威王分别会派出一匹马,每匹马每天只能上场一次,每场比赛的精彩程度是上场的两匹马的速度之和。为了让比赛更精彩,任意不同的两天里进行的比赛不能完全相同,也就是说,对于任意不同的两天,存在至少一匹马在这两天比赛的对手不同。你需要计算出这 k 天总计 k×n 场比赛中精彩程度最小值的最大可能值。
二分答案,对每个答案用乘法原理算出解,注意无解。
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
#define
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
int n,k;
ll a[500],b[500];
bool check(ll m) {
int j=n+1;
__int128 ans=1;
For(i,n) {
while(j>1 && a[i]+b[j-1] >=m) --j;
int t=n+1-j;
if(!t) return 0;
if(t<i) return 0;
}
j=n+1;
For(i,n) {
while(j>1 && a[i]+b[j-1] >=m) --j;
int t=n+1-j;
ans*=t-i+1;
if(ans>=k) return 1;
}
return 0;
}
int main()
{
// freopen("C.in","r",stdin);
// freopen(".out","w",stdout);
cin>>n>>k;
For(i,n) a[i]=read();
For(i,n) b[i]=read();
sort(a+1,a+1+n);
sort(b+1,b+1+n);
ll l=1,r=1e9*50LL,ans=l;
while(l<=r) {
ll m=(l+r)/2;
if(check(m))ans=m,l=m+1;
else r=m-1;
}
cout<<ans<<endl;
return 0;
}