I was wondering how best to optimize the solution for PRITREE. The way I approached was I generated random trees and permuted the values among their nodes and kept saving the best one. I even kept partitioning the primes to the leaves with some probability.

I was wondering how better to solve this (I couldn’t find the editorial link for this).

Link to my solution

P.S: This is my first attempt at a Challenge problem.