Newcoder 26 D.世界上最可爱的珂朵莉(贪心)

142 篇文章 0 订阅

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 1in满足 a i ≥ b i a_i\ge b_i aibi

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) (0n2105,0x,y2109,0ai,bi2109)

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 biai的差值最大值

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值