Initialize a sum to and add each score once. After processing scores, the sum equals exactly their total, so after all scores it is the answer. Time complexity is and auxiliary space is . The maximum sum is . A naive solution may add once for each point; at most updates are needed.
Solution written by GPT6.1