Each process has an array(size = m) of resources allocated to it.
Ex: $$P_i = [r_1, r_2, r_3, ...., r_m]$$
To check for a safe state:
In first loop, we may find a process that can be executed with the available resources and this takes O(mn).
In second loop, we have (n-1) processes and time complexity is O((n-1)m).
...
...
In last loop, we need to check for that single process whether it can be executed or not, time complexity = O(m)
So, total time complexity = $$O(m(n+(n-1)+(n-2)+.....+1)) = O(m^1n^2)$$
a = 1, b = 2