My issue
give me correct code
My code
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int T;
std::cin >> T; // Read number of test cases
std::vector<int> results;
for (int i = 0; i < T; ++i) {
int X, Y;
std::cin >> X >> Y; // Read values of X and Y
// Initialize the minimum operations needed to a large number
int min_operations = std::numeric_limits<int>::max();
// Check for the condition X >= 2Y
if (X < 2 * Y) {
int operations_needed = 2 * Y - X;
min_operations = std::min(min_operations, operations_needed);
} else {
min_operations = 0; // Condition already satisfied
}
// Check for the condition Y >= 2X
if (Y < 2 * X) {
int operations_needed = 2 * X - Y;
min_operations = std::min(min_operations, operations_needed);
} else {
min_operations = 0; // Condition already satisfied
}
results.push_back(min_operations);
}
// Print results for each test case
for (const auto& result : results) {
std::cout << result << std::endl;
}
return 0;
}
Problem Link: Ratio By 2 Practice Coding Problem