The problem statement is as follows:
An insulated rigid vessel of volume $V$ initially contains $N_i$ moles of an ideal gas at temperature $T_i$. A pipe is now connected to the vessel and the same type of gas (but held at a different constant temperature $T_\text{in}$ in the pipe) is slowly pumped into the vessel until the total number of moles in the vessel becomes $N_f$. Obtain an explicit expression for the final temperature in the vessel in the form $T_f = f(T_i, T_\text{in}, N_f/N_i, \gamma)$ where $\gamma = C_p/C_v$, the ratio of molar isobaric heat capacity of the gas $C_p$ to the molar isochoric heat capacity of the gas $C_v$, both of which are independent of temperature. Assume there is negligible heat transfer between the gas in the tank and the vessel walls during the process.
My thoughts are that the energy it takes to heat the initial moles in the tank, $N_i$, to the final temperature, $T_f$, is equal to $(N_i)(C_v)(T_f-T_i)$. Would this be equal to the energy lost by the incoming gas $(N_f-N_i)(C_p)(T_\text{in}-T_f)$? Then all one would need to do is isolate $T_f$ in terms of the other variables. I am unsure if I'm missing some energy term and if my equating of $\Delta U$ of the preexisting gas to the $\Delta H$ of the incoming gas is correct.