9/2/25, 10:27 AM Problem - 2005B1 - Codeforces
|
stdfloat | Logout
HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN
PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST
Codeforces Round 972 (Div. 2)
B1. The Strict Teacher (Easy Version) Finished
time limit per test: 1.5 seconds Practice
memory limit per test: 256 megabytes
This is the easy version of the problem. The only differences between the two versions are the constraints
on m and q . In this version, m = 2 and q = 1 . You can make hacks only if both versions of the problem
are solved. → Virtual participation
Virtual contest is a way to take part in past contest,
Narek and Tsovak were busy preparing this round, so they have not managed to do their homework and decided to as close as possible to participation on time. It is
steal David's homework. Their strict teacher noticed that David has no homework and now wants to punish him. supported only ICPC mode for virtual contests. If
you've seen these problems, a virtual contest is not
She hires other teachers to help her catch David. And now m teachers together are chasing him. Luckily, the for you - solve these problems in the archive. If you
just want to solve some problem from a contest, a
classroom is big, so David has many places to hide. virtual contest is not for you - solve this problem in
the archive. Never use someone else's code, read
The classroom can be represented as a one-dimensional line with cells from 1 to n , inclusive. the tutorials or communicate with other person
during a virtual contest.
At the start, all m teachers and David are in distinct cells. Then they make moves. During each move Start virtual contest
David goes to an adjacent cell or stays at the current one.
Then, each of the m teachers simultaneously goes to an adjacent cell or stays at the current one.
→ Clone Contest to Mashup
This continues until David is caught. David is caught if any of the teachers (possibly more than one) is located in the
same cell as David. Everyone sees others' moves, so they all act optimally. → Submit?
Your task is to find how many moves it will take for the teachers to catch David if they all act optimally.
Language: GNU G++20 13.2 (64 bit, winlibs)
Acting optimally means the student makes his moves in a way that maximizes the number of moves the teachers
Choose
need to catch him; and the teachers coordinate with each other to make their moves in a way that minimizes the file:
Choose File No file chosen
number of moves they need to catch the student.
Submit
Also, as Narek and Tsovak think this task is easy, they decided to give you q queries on David's position. Note: this
is the easy version, and you are given only one query.
→ Contest materials
Input
5
In the first line of the input, you are given a single integer t (1 ≤ t ≤ 10 ) — the number of test cases. The Announcement (en)
description of each test case follows.
Tutorial #1 (en)
In the first line of each test case, you are given three integers n , m , and q (3 ≤ n ≤ 10
9
,m ,
= 2 q = 1 ) — the Tutorial #2 (en)
number of cells on the line, the number of teachers, and the number of queries.
Video Editorial (en)
In the second line of each test case, you are given m distinct integers b1 , b2 , … , bm (1 ≤ bi ≤ n ) — the cell
numbers of the teachers.
→ CF GetRating
In the third line of each test case, you are given q integers a1 , a2 , … , aq (1 ≤ ai ≤ n ) — David's cell number for
every query. *1000
It is guaranteed that for any i , j such that 1 ≤ i ≤ m and 1 ,
≤ j ≤ q bi ≠ aj . Show All Tags
Contest Standings
Output
For each test case, output q lines, the i -th of them containing the answer of the i -th query.
Example
input Copy
3
10 2 1
1 4
2
8 2 1
3 6
1
8 2 1
3 6
8
output Copy
1
2
2
Note
In the first example, the student can just stay at cell 2 . The teacher, initially located in cell 1 , can reach cell 2 in one
move. Therefore, the answer is 1 .
In the second example, the student should just stay at cell 1 . The teacher, initially located in cell 3 , can reach cell 1
in two moves. Therefore, the answer is 2 .
https://codeforces.com/problemset/problem/2005/B1 1/2
9/2/25, 10:27 AM Problem - 2005B1 - Codeforces
Codeforces (c) Copyright 2010-2025 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Sep/02/2025 10:25:08UTC+5 (h1).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions
Supported by
https://codeforces.com/problemset/problem/2005/B1 2/2