C - Min Difference - AtCoder Beginner 212(排序双指针)

本文介绍了一种使用排序双指针解决在两个整数序列中找到最小差值绝对值的方法。通过避免暴力求解,而是对序列进行排序后用双指针策略,可以有效应对大规模数据。文章提供了样例输入和输出,并详细解释了思路及代码实现。
摘要由CSDN通过智能技术生成

题目描述:

You are given two sequences: A=(A1,A2,…,AN) consisting of N positive integers, and B=(B1,…,BM) consisting of M positive integers.

Find the minimum difference of an element of A and an element of B, that is, min1≤i≤Nmin1≤j≤M|Ai−Bj|.

数据范围:

  • 1≤N,M≤2×10^5

  • 1≤Ai≤10^9

  • 1≤Bi≤10^9

  • All values in input are integers.

输入:

Input is given from Standard Input in the following format:

N M

A1 A2 …… AN

B1 B2 …… BM

输出:

Print the answer.

样例输入1:

2 2

1 6

4 9

样例输出1:

2

Here is the difference for each of the four pair of an element of A and an element of B: |1−4|=3, |1−9|=8, |6−4|=2, and |6−9|=3. We should print the minimum of the

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值