I'm working on a greedy algorithm that will take 3 inputs (m, n, t). m and n are the time it takes to finish one task (both tasks are equal in value) and t is the time given to finish those tasks. I have to maximize the amount of tasks finished (can be as many m or n as I can take, or a combination of both) while making sure that

**t is kept to a minimum**. I then have to print out the amount of tasks completed and the time not spent.

I thought about this for a while and came up with the idea that if the minimum of (m, n) divides evenly into t then that maximizes the tasks finished and minimizes time not spent doing the tasks. For example,

if 3 2 10 is input then 5 0 will be the output.

The code I have done so far looks like this: (where store[] is the array that is storing the numbers]

for(int j = 0; j < store.length; j += 3){ m = store[j]; n = store[j+1]; t = store[j+2]; if(m > n){ if(t % n == 0){ sum = t / n; //see how many times n goes into t count = t % n; System.out.println(sum + " " + count); } } if(n > m){ if(t % m == 0){ sum = t / m; count = t % m; System.out.println(sum + " " + count); } } }

My problem is this: what do I do when there isn't a simple answer, like the above code checks for. How do I handle if the input is, say, 5 41 112. 8 0 is the output I want (2 x 41 and 6 x 5), how do I go about getting this done?