--- Final Solver (used for performance test) ---
import numpy as np
from typing import Any


class Solver:
    def solve(self, problem: dict[str, Any], **kwargs) -> dict[str, Any]:
        y = np.asarray(problem["y"], dtype=np.float64).ravel()
        n = len(y)

        # Sort descending
        sorted_y = -np.sort(-y)

        # Find rho and theta in one pass with minimal allocations
        # cumsum is already computed by numpy cumsum, but we do it inline
        # to avoid extra intermediate arrays
        rho = 0
        cumsum = 0.0
        rho_cumsum = 0.0
        for j in range(n):
            cumsum += sorted_y[j]
            if sorted_y[j] > (cumsum - 1.0) / (j + 1):
                rho = j
                rho_cumsum = cumsum

        theta = (rho_cumsum - 1.0) / (rho + 1)

        # Compute result
        x = np.empty(n)
        np.subtract(y, theta, out=x)
        np.maximum(x, 0.0, out=x)

        return {"solution": x}
--- End Solver ---
Running performance test...
============================= test session starts ==============================
platform linux -- Python 3.12.13, pytest-9.0.2, pluggy-1.6.0
rootdir: /tests
plugins: anyio-4.13.0, jaxtyping-0.3.9
collected 3 items

../tests/test_outputs.py .
--- Performance Summary ---
Validity: True
Total Baseline Time: 6.5807s
Total Solver Time:   24.6629s
Raw Speedup:         0.2668 x
Final Reward (Score): 1.0000
---------------------------
.F

=================================== FAILURES ===================================
_____________________________ test_solver_speedup ______________________________

performance_results = {'raw_speedup': 0.2668274085700555, 'speedup': 1.0, 'validity': True}

    def test_solver_speedup(performance_results):
        """Checks if the solver effectively optimized the code."""
>       assert performance_results["raw_speedup"] > 1.0, \
            f"Solver was not faster than baseline (Speedup: {performance_results['raw_speedup']:.2f}x)"
E       AssertionError: Solver was not faster than baseline (Speedup: 0.27x)
E       assert 0.2668274085700555 > 1.0

/tests/test_outputs.py:205: AssertionError
==================================== PASSES ====================================
=========================== short test summary info ============================
PASSED ../tests/test_outputs.py::test_solver_exists
PASSED ../tests/test_outputs.py::test_solver_validity
FAILED ../tests/test_outputs.py::test_solver_speedup - AssertionError: Solver...
=================== 1 failed, 2 passed in 522.14s (0:08:42) ====================
