Help required in USACO problem!


I have been stuck at this problem for a few days I have seen the editorial but I don’t understand how they arrived at this formula:

long maxmatch = n - x*y;
long numdays = (maxmatch - g) / y + 1;

It is the consecutive number of days, such that y remains unchanged, please help me understand how to arrive at this formula. Thanks!