Fungus gnats and a Nitrogen deficiency is two different things.
The fungus gnats won’t harm your plants, they will just stick all over your buds like they do on sticky pads.
You can try to control them with yellow stickers, put diatomaceous earth or sand or straws on top of the soil.
The yellow leaves are a Nitrogen deficiency. It happens around week 4 of flowering when the plants haven’t got enough Nitrogen during the stretch. It’s called the Die-Back , the plant is moving its Nitrogen from the bottom to save the top. It’s too late to add more Nitrogen as the roots are only processing P and K for the flowers now. Just let it do her thing, do not unplug any leaves before it has completely turned yellow and moved all the Nitrogen, don’t worry for your smoke and buds, the plant is going to regulate the Nitrogen until the harvest, you’re just gonna lose some leaves before the flush, nothing really bad...