PROBLEM LINK:
Setter: utkarsh_25dec
Testers: iceknight1093
DIFFICULTY:
819
PREREQUISITES:
None
PROBLEM:
Given the position of two people on the integer line, choose ameeting point such that the maximum distance traveled by either of them is minimized.
EXPLANATION:
We try to place the meeting point at the mid point. We need to be careful about the case where the distance between them isn’t even. So we take the ceiling.
TIME COMPLEXITY:
Time complexity is O(1).
SOLUTION:
Editorialist's Solution
#include <iostream>
#include <cmath>
using namespace std;
int T,x,y;
int main() {
cin>>T;
while(T--)
{
cin>>x>>y;
cout<<ceil((max(x,y)-min(x,y))/2.0)<<"\n";
}
return 0;
}
Tester's Solution
for _ in range(int(input())):
x, y = map(int, input().split())
print((abs(x-y)+1)//2)