classSolution{public:// Same as 3205. Maximum Array Hopping Score IlonglongmaxScore(vector<int>&nums){// The optimal jump is the maximum number in the remaining suffix.longans=0;intmx=0;for(inti=nums.size()-1;i>0;--i){mx=max(mx,nums[i]);ans+=mx;}returnans;}};
1 2 3 4 5 6 7 8 9101112131415
classSolution{// Same as 3205. Maximum Array Hopping Score IpubliclongmaxScore(int[]nums){// The optimal jump is the maximum number in the remaining suffix.longans=0;intmx=0;for(inti=nums.length-1;i>0;--i){mx=Math.max(mx,nums[i]);ans+=mx;}returnans;}}
12345
classSolution:# Same as 3205. Maximum Array Hopping Score IdefmaxScore(self,nums:list[int])->int:# The optimal jump is the maximum number in the remaining suffix.returnsum(itertools.accumulate(nums[:0:-1],max))