Ratio By 2

This code takes multiple test cases and checks if one value is at least double the other. If true, it outputs 0. Otherwise, it calculates the minimum of two possible adjustments (y reduced by half of x or x reduced by half of y) and prints the result.

include <bits/stdc++.h>
using namespace std;

int main() {

int t;
cin>>t;

while(t--){
    int x, y;
	cin>>x>>y;
	if (y >= 2*x || x >= 2*y) cout<<0<<endl;
	else cout<<min (y - (x/2), x - (y/2)) <<endl;
}
return 0;

}

The time complexity is 𝑂(𝑡), and the space complexity is 𝑂 (1), where t is the number of test cases.

:+1: