B. Bobritto Bandito
time limit per test
1 second
memory limit per test
256 megabytes
In Bobritto Bandito's home town of residence, there are an infinite number of houses on an infinite number line, with houses at …,−2,−1,0,1,2,…. On day 0, he started a plague by giving an infection to the unfortunate residents of house 0. Each succeeding day, the plague spreads to exactly one healthy household that is next to an infected household. It can be shown that each day the infected houses form a continuous segment.
Let the segment starting at the l-th house and ending at the r-th house be denoted as [l,r]. You know that after n days, the segment [l,r] became infected. Find any such segment [l′,r′] that could have been infected on the m-th day (m≤n).
Input
The first line contains an integer t (1≤t≤100) – the number of independent test cases.
The only line of each test case contains four integers n, m, l, and r (1≤m≤n≤2000,−n≤l≤0≤r≤n,r−l=n).
Output
For each test case, output two integers l′ and r′ on a new line. If there are multiple solutions, output any.
Example
Input
Copy
4
4 2 -2 2
4 1 0 4
3 3 -1 2
9 8 -6 3
Output
Copy
-1 1 0 1 -1 2 -5 3
Note
In the first test case, it is possible that on the 1-st, 2-nd, and 3-rd days the interval of houses affected is [−1,0], [−1,1], [−2,1]. Therefore, [−1,1] is a valid output.
解题说明:此题是一道几何题,其实就是从坐标0点开始,m天后能到达的点。这里要做一个判断,比较l和-m的大小,如果l小,则直接输出-m到0即可。如果l大,等于m>-l,,为了限定在l,r范围内,可以选择l到m+l这个范围。
#include <stdio.h>
int main()
{int t;scanf("%d", &t);while (t--){int n, m, l, r;scanf("%d %d %d %d", &n, &m, &l, &r);int L = 0, R = 0;if (l <= -m){printf("%d 0\n", -m);}else{printf("%d %d\n", l, m + l);}}return 0;
}