题目链接:https://www.nowcoder.com/acm/contest/26/D
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 65536K,其他语言131072K
64bit IO Format: %lld
空间限制:C/C++ 65536K,其他语言131072K
64bit IO Format: %lld
题目描述
我永远喜欢珂朵莉~!
有两个长为n的序列a[i]与b[i]
你可以把任意不多于x个a序列中的数变成y
你可以把所有序列b中的数减去一个非负数t
你可以把a序列和b序列分别任意打乱
要求对于1 <= i <= n满足a[i] >= b[i]
求t的最小值
输入描述:
第一行三个数n,x,y 之后一行n个数表示a序列 之后一行n个数表示b序列
输出描述:
一行一个非负数表示答案
示例1
输入
10 0 233333 227849 218610 5732 128584 21857 183426 199367 211615 91725 110029 8064826 14174520 10263202 9863592 592727 7376631 5733314 1062933 12458325 15046167
输出
14818318
备注:
对于100%的数据,0 <= n <= 200000 , 0 <= x,y <= 2000000000 0<=a[i],b[i]<=2000000000
解析:其实就是对比两个序列,对于a[n],排下序,把前x变小与y的变成y,然后再拍下序和b[n]对比找差值最大的就好了,最水的一个题
代码:
#include<bits/stdc++.h>
using namespace std;
int a[200009], b[200009];
int main()
{
int n, x, y;
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 < n; i++)
{
if(x && a[i] < y) a[i] = y, x--;
if(x <= 0 || a[i] > y) break;
}
sort(a, a+n);
int ans = 0;
for(int i = 0; i < n; i++) ans = max(ans, b[i]-a[i]);
printf("%d\n", ans);
return 0;
}