faster sample_upper_bound and sort x_init in main