Maintain diagonal symmetry when placing N items on a square grid Write a program that takes in two non-negative integers S and N in that order. S represents the side length of a square grid of . characters. N represents the number of those .'s that need to be changed to x's. You may assume N is no greater than S squared.
Your program needs to output this S×S square of .'s and N x's but the requirement is that the square must always have a diagonal line of symmetry from its top left to its bottom right. Any grid arrangement is valid output as long as it has this symmetry.
For example, if S is 3 and N is 4 here are several grids that have this diagonal symmetry and would be valid output:
x.x
...
x.x

x..
.xx
.x.

...
.xx
.xx

The following grids however would not be valid:
.x.
xxx
...
(lacks diagonal symmetry)

..x
xx.
.x.
(has diagonal symmetry but not from the top left to the bottom right)

x.x
.x.
x.x
(incorrect number of x's)

This is code golf so the shortest program in bytes wins!
Details:

A trailing newline after the grid is fine.

You may use any two distinct printable-ASCII characters in place of . and x if you prefer.

If you prefer you may even output a binary-matrix instead of a string.

When N is 0 the output will be a pure S×S square of .'s with no x's.

When S is 0 the output will be an empty string (or single trailing newline).

The output does not need to be deterministic, as long as it is always guaranteed to be valid.


More Examples:
Not all valid arrangements are listed for each example input. Your output might look different yet still be valid.
S = 0, N = 0
[empty string]

S = 1, N = 0
.

S = 1, N = 1
x

S = 2, N = 0
..
..

S = 2, N = 1
x.
..

..
.x

S = 2, N = 2
x.
.x

.x
x.

S = 2, N = 3
xx
x.

.x
xx

S = 2, N = 4
xx
xx

S = 3, N = 2
x..
.x.
...

..x
...
x..

S = 4, N = 1
....
.x..
....
....

S = 4, N = 5
x..x
.x..
..x.
x...

xxx.
x...
x...
....

S = 5, N = 23
xxxxx
xxxxx
xxxxx
xxx.x
xxxx.

xxxxx
xxxxx
xxxxx
xxxx.
xxx.x

S = 7, N = 13
...x...
...x...
...x...
xxxxxxx
...x...
...x...
...x...

xxxxxxx
x......
x......
x......
x......
x......
x......
Python 2, 116 113 112 101 bytes

lambda s,n:[[[n&gt;i&lt;s-(s+n&amp;1),[i*~-i+2*j,j*~-j+2*i][i&lt;j]&lt;n-s][j!=i]for j in range(s)]for i in range(s)]

Try it online!
Input: 2 integers s and n
Output: A 2D list of True and False, representing x and . respectively.
Explanation
The strategy is to put as many xs on the diagonal as possible.

If \$s\$ and \$n\$ has the same parity, then we can fill \$min(s,n)\$ diagonal squares.
If \$s\$ and \$n\$ has different parity, then we can fill \$min(s-1,n)\$ diagonal squares.

The remaining xs can be split symmetrically between the 2 triangular half of the grid. For the bottom triangle, we fill from top to bottom, where each row is filled left to right. The upper triangle mirrors the bottom triangle (fill left to right, each column from top to bottom)
Thus, we can determine if a square is filled just based on its indices \$(i,j)\$:

If \$i=j\$ (the square is on the diagonal), then that square is filled if \$i&lt;n\$ and \$i&lt;s-t\$, where \$t\$ is 0 or 1 depending on whether \$s\$ and \$n\$ have the same or different parity.
The following snippet evaluates to True or False if the diagonal square should be filled or not.

[n&gt;i&lt;s-(s+n&amp;1), ...case when square is not diagonal... ][j!=i]


If \$i&gt;j\$ (the square is in lower triangle), then the number of squares in the lower triangle before this square (in fill order) is \$m = \frac{i(i-1)}{2} + j\$. Thus if this square is filled, then the number of squares filled before it is \$2m = i(i-1)+2j\$. We need to make sure that \$2m&lt;n-s\$, otherwise the diagonal cannot be filled to the maximum.
Similarly, if \$i&gt;j\$, then we fill if \$j(j-1)+2i&lt;n-s\$.
The following snippet evaluates to True or False if the non-diagonal square is filled or not:

[i*~-i+2*j,j*~-j+2*i][i&lt;j]&lt;n-s

Combined together, this big expression evaluates to whether a square \$(i,j)\$ should be filled:
[n&gt;i&lt;s-(s+n&amp;1),[i*~-i+2*j,j*~-j+2*i][i&lt;j]&lt;n-s][j!=i]

Thanks @ovs for saving 4 bytes in a previous solution!