#C6630. Checkpoint Challenge: Maximum Score
Checkpoint Challenge: Maximum Score
Checkpoint Challenge: Maximum Score
You are given a series of checkpoints, each with a certain score. Your task is to determine the maximum cumulative score you can obtain by starting at one checkpoint and continuing through subsequent checkpoints in a contiguous manner.
More formally, you are given an integer \( n \) and a list of \( n \) integers \( arr \), where each integer represents the score at that checkpoint. You need to find the maximum sum of a contiguous subarray of \( arr \). Note that if all scores are negative, the maximum score corresponds to the largest (i.e., least negative) single element.
This is a classic problem that can be solved using Kadane's Algorithm or other similar approaches.
inputFormat
The input is given through stdin with the following format:
The first line contains an integer \( n \) \( (1 \leq n \leq 10^5) \), the number of checkpoints. The second line contains \( n \) space-separated integers, where each integer is the score at a checkpoint. Each score value fits in a standard 32-bit signed integer.
outputFormat
Output the maximum cumulative score that can be achieved by selecting an optimal contiguous segment of checkpoints, printing the result to stdout.
## sample5
-3 2 5 -1 4
10