Find the most combinations of two numbers that equal third or get close to it
Have you simply tried to split code into smaller functions?

int t = in.nextInt(); //Time available


How about simply naming it timeAvailable instead of t ?

if(m &gt; n) { //I rearrange my input as it doesn't work when m is bigger then n
    int tmp = m;
    m = n;
    n = tmp;
}


Common pattern is something like:

int calculate(int m, int n, int t) {
    if (m &gt; n) {
        return calculate(n, m, t);
    }
    ...
}


Try to declare variables in smallest possible scope - int tmpgap; should be inside the for-loop. The inner for-loop might be replaced by division + Math.floor().