Suppose $p>q$, $X\sim \text{Bernoulli}(p)$, $Y\sim \text{Bernoulli}(q)$. Couple $X$ and $Y$ to maximise $P(X=Y)$. My professor's solution to this is as follows: "Create a 2 x 2 matrix with the first row (corresponding to $X=0$) summing to $P(X=0)=1-p$, the second row summing to $P(X=1)=p$, the first column ($Y=0$) summing to $P(Y=0)=1-q$ and the second column summing to $P(Y=1)=q$. We want to maximize the sum of the diagonal which is $P(X=Y)$. Since $p > q$, the first diagonal entry can be at most $1 − p$; the second can be at
most $q$. If we write these in we can fill out the rest of the table (below) to get the desired coupling."

The bit I'm confused about is why $p>q$ implies the first diagonal entry can be at most $1-p$? Can someone explain this please? If we want to maximise the sum of the main diagonal then isn't $1-q+p$ better than $1-p+q$ because $p>q \implies 1-p+q<1$ but $1-q+p>1$?

Here is a simple solution:
Pick a random number $z$ uniformly in $[0,1]$
for $0 \le z<q$ set $X=Y=1$;
for $q \le z<p$ set $X=1,Y=0$;
for $ p \le z \le 1$ set $X=Y=0$.

But if you prefer to do it using table you have to complete the following table:

The first row have to has sum equal to $1-q$ and the second one equal to $q$
[Analogously for the columns.]
The digonal entries have to be equal to minimum of the corresponding row and column probability since you want to maximaize $P(X=Y)$
[If you set a value greater than this minimum you have to set a negative value for the other entry!]
So you can complete the table as your professor said.

P.S. My table is transpose of yours.

