## 3 Secure Rate Maximization Scheme
### K-Means Cluster Pair Algorithm  
The detailed process of the K-means pair cluster algorithm is shown in Algorithm 1. This algorithm can maximize the total secure rate by reducing the horizontal Euclidean distance between the UAV and users. Afterward, the centroid of the clusters is set to be the UAVs' optimal horizontal coordinate \(\mathbf{Q}^{*}\) and the NOMA pair is also determined, where such a setting is optimal regardless of how the channel, power, and height change [24]. ```
1:Set \(i=0\) and choose \(M\) points as the initial center, \(\mathrm{center}_{m}^{0}\in\left\{\mathrm{center}_{1}^{0},\mathrm{center}_{2 }^{0},...,\mathrm{center}_{M}^{0}\right\}\). 2:repeat
3: Compute the distance from users to \(\mathrm{center}_{m}^{i}\), \(m=1,2,...,M\). 4: Sort the users close to \(\mathrm{center}_{m}^{i}\) into \(\mathrm{cluster}_{m}\), where the mean value of those sorted users' coordinates is the new center of \(\mathrm{cluster}_{m}\) denoted by \(\mathrm{center}_{m}^{j+1}\). 5:\(i=i+1\). 6:until convergence. 7: The \(\mathrm{UAV}_{m}\)'s horizontal coordinates is \(\mathrm{center}_{m}^{i+1}\)
8: Categorize half of the users closest to the UAV as adjacent users and others as distant users. 9:repeat
10: Calculate the distance between the distant users and the adjacent users. 11: The one with the shorter distance is formed as a NOMA pair and will be removed in the next calculation. 12:until Each distant user matches an adjacent user. ### Resource Allocation

First, given the optimal horizontal coordinates of UAVs \(\mathbf{Q}^{*}\), it is expected to maximize the total secure rate by optimizing the remaining three variables, \(\mathbf{A},\mathbf{P},\mathbf{H}\). Second, the operator\([\bullet]^{+}\), making the objective functions of P1 nonsmooth at zero value, can be omitted in the optimal case which has been proved in detail in Lemma 1 of [25]. Thus, the original problem can be written as follows:

\[\text{P2}: \max\limits_{\mathbf{A},\mathbf{P},\mathbf{H}}\sum\limits_{m=1}^{M }\sum\limits_{k=1}^{K}\sum\limits_{p=1}^{N_{p}}a_{m,k}\hat{R}_{p}^{\text{sec}}, \tag{13}\] \[\text{s.t.}(8),(9),(10),(11),(12),\]

where \(\hat{R}_{p}^{\text{sec}}=\min\{\left[P_{a}^{D\to l}-r_{a}^{D\to E}\right], \left[r_{l}-r_{E}\right]\}+\min\{\left[r_{d}^{D\to l}-r_{d}^{D\to E}\right], \left[r_{l}-r_{E}\right]\}\). Since the problem P2 is obviously a non-deterministic polynomial (NP)-hard problem with three coupled variables, whose analytical solution is difficult to find, hence we use the BCD algorithm, a typical deterministic method for dealing with non-convex issues [26; 27; 28], to decouple the original problem into three subproblems. #### 3.2.1 Channel Allocation

Initially, the users' transmission power and UAVs' height are fixed to optimize the channel allocation, the binary factor \(a_{m,k}\) is slacked to continuous variables \(\hat{a}_{m,k}\) and the optimization problem P2 can be written as

\[\text{P3.1}: \max\limits_{\mathbf{A}} \sum\limits_{m=1}^{M}\sum\limits_{k=1}^{K}\sum\limits_{p=1}^{N_{p }}\hat{a}_{m,k}\hat{R}_{p}^{\text{sec}}, \tag{14}\] \[\text{s.t.} \sum\limits_{m=1}^{M}\sum\limits_{k=1}^{K}\hat{a}_{m,k}\leqslant 1,\hat{a}_{m,k}\in[0,1],\forall m,\forall k. \tag{15}\]

It is obvious that problem P3.1 is a linear programming problem and can be solved by MATLAB toolbox CVX. This relaxation technique can transform the integer program optimization problem into a linear programming problem, where the decimal solution of the relaxed linear program is the upper limit of the original problem and consequently the ultimate integer solution can be obtained by relaxation transform. #### 3.2.2 Power Optimization

In this stage, the transmission power of users is optimized with the channel allocation and height of UAVs fixed.