307369: CF1346G. Two IP Cameras
Memory Limit:256 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Two IP Cameras
题意翻译
你有 $2$ 台自动摄像机,这两台摄像机开机之后,每过一段时间就会拍一张照片(开机时也拍)。你有 $k$ 个拍照间隔可以选择,分别为 $p_1,p_2,...,p_k$。你想要在 $n$ 个时间点拍照,分别为 $x_1,x_2,...,x_n$,你必须使用这两台照相机并且中途不能关机,请你选定每台摄像机的开机时间(任意)、摄像间隔,使 $n$ 个拍照时间点都可以被拍到(可以拍多余的照片)。 若有多解,输出任意一组。给出的 $x,p$ 数组皆**递增**。 - 请注意,本题只能使用 `Kotlin` 语言提交,提交时请使用 `Kotlin` 语言,并且选择 `Kotlin/JVM` 选项题目描述
You have two IP cameras of the same model. Each camera can take photos starting from some moment of time with a fixed period. You can freely choose the starting moment but you can choose the period only as one of $ k $ values $ p_1, p_2, \dots, p_k $ which are chosen by the camera's manufacturer. You have $ n $ moments of interest $ x_1, x_2, \dots, x_n $ . You'd like to configure both cameras in such a way that at least one camera will take a photo in each of these moments. Configuring the camera means setting the moment when it takes the first photo and the gap between two consecutive photos (which should be one of the values $ p_1, p_2, \dots, p_k $ ). It's not a problem for you that cameras can take photos at other moments of time — you only care about moments of interest.输入输出格式
输入格式
The first line contains two integers $ k $ and $ n $ ( $ 1 \le k \le 10^5 $ ; $ 2 \le n \le 10^5 $ ) — the number of periods to choose and the number of moments of interest. The second line contains $ k $ integers $ p_1, p_2, \dots, p_k $ ( $ 1 \le p_1 < p_2 < \dots < p_k \le 10^6 $ ) — the periods to choose in the ascending order. The third line contains $ n $ integers $ x_1, x_2, \dots, x_n $ ( $ 1 \le x_1 < x_2 < \dots < x_n \le 10^6 $ ) — the moments of interest in the ascending order.
输出格式
Print YES (case insensitive) in the first line if there is a way to configure cameras. In the second line, print two integers $ s_1 $ and $ cp_1 $ ( $ 1 \le s_1 \le 10^6 $ ; $ 1 \le cp_1 \le 10^6 $ ; $ cp_1 \in \{p_1, \dots, p_k\} $ ) — the starting moment and the period for the first camera. The period should be one of the given periods. In the third line, print two integers $ s_2 $ and $ cp_2 $ ( $ 1 \le s_2 \le 10^6 $ ; $ 1 \le cp_2 \le 10^6 $ ; $ cp_2 \in \{p_1, \dots, p_k\} $ ) — the starting moment and the period for the second camera. The period should be one of the given periods. If there is no way to configure cameras, print NO (case insensitive). If there are multiple ways, you may print any of them.
输入输出样例
输入样例 #1
3 5
3 5 7
1 4 5 7 12
输出样例 #1
YES
1 3
5 7
输入样例 #2
3 2
1 2 3
1 10
输出样例 #2
YES
1 1
10 1
输入样例 #3
3 4
1 2 3
5 7 9 11
输出样例 #3
YES
5 1
5 1
输入样例 #4
3 4
10 20 100
2 3 4 7
输出样例 #4
NO