Description
我永远喜欢珂朵莉~!
有两个长为 n n n的序列 a i a_i ai与 b i b_i bi
你可以把任意不多于 x x x个 a a a序列中的数变成 y y y
你可以把所有序列 b b b中的数减去一个非负数 t t t
你可以把 a a a序列和 b b b序列分别任意打乱
要求对于 1 ≤ i ≤ n 1\le i \le n 1≤i≤n满足 a i ≥ b i a_i\ge b_i ai≥bi
求 t t t的最小值
Input
第一行三个数 n , x , y n,x,y n,x,y
之后一行 n n n个数表示 a a a序列
之后一行 n n n个数表示 b b b序列
( 0 ≤ n ≤ 2 ⋅ 1 0 5 , 0 ≤ x , y ≤ 2 ⋅ 1 0 9 , 0 ≤ a i , b i ≤ 2 ⋅ 1 0 9 ) (0\le n\le 2\cdot 10^5,0\le x,y\le 2\cdot 10^9,0\le a_i,b_i\le 2\cdot 10^9) (0≤n≤2⋅105,0≤x,y≤2⋅109,0≤ai,bi≤2⋅109)
Output
一行一个非负数表示答案
Sample Input
10 0 233333
227849 218610 5732 128584 21857 183426 199367 211615 91725 110029
8064826 14174520 10263202 9863592 592727 7376631 5733314 1062933 12458325 15046167
Sample Output
14818318
Solution
先尽可能把 a a a序列较小值换成 y y y,之后把两个序列升序排之后,答案即为 b i − a i b_i-a_i bi−ai的差值最大值
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=200005;
int n,a[maxn],b[maxn],x,y;
int main()
{
scanf("%d%d%d",&n,&x,&y);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
for(int i=0;i<n;i++)scanf("%d",&b[i]);
sort(a,a+n),sort(b,b+n);
for(int i=0;i<x;i++)
if(a[i]<y)a[i]=y;
sort(a,a+n);
int ans=0;
for(int i=0;i<n;i++)ans=max(ans,max(b[i]-a[i],0));
printf("%d\n",ans);
return 0;
}