Help me in solving MAX_DIFF problem

My issue

My code

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

void solution()
{
    int N, S, minimum = 0;
	cin >> N >> S;
	minimum = min(N, S);

	
    for(int i = 0; i < 2 * N; i++)
    {
        if(i + minimum == S)
        {
            cout << abs(minimum - i) << endl;
            break;
        }
    }
}

int main() {
	// your code goes here
	int T;
	cin >> T;
	while(T--)
	{
        solution();
	}
	return 0;
}
//i have get its solution but didnt get its concept can anybody explain it please 

Problem Link: CodeChef: Practical coding for everyone