The two main problems in cognitive radio networks are power and time slot allocation problems which require a precise analysis and guarantee the quality of service in both the primary and secondary users. In this paper, these two problems are considered and a method is proposed to solve the resulting optimization problem. Our proposed method provides an improved performance in solving the constrained nonlinear multiobject optimization for the power control and beamforming in order to reach the maximum capacity and proper adaption of time slots, and as a result a new scheme for joint power and time slot allocation in cognitive relay networks is proposed. We adopt space diversity access as the secondary users access scheme and divide the time between multiple secondary users according to their contribution to primary user's transmission. Helping primary users provides more opportunities for secondary users to access the channel since the primary users can release the channel sooner. In contrast, primary network leases portion of channel access time to the secondary users for their transmission using particle swarm optimization (PSO). Numerical studies show good performance of the proposed scheme with a dynamic cost function in a nonstationary environment.