1793.cpp (501B)
1 class Solution { 2 public: 3 int maximumScore(const vector<int> &nums, int k) { 4 const int n = nums.size(); 5 int left = k - 1, right = k + 1, res = nums[k], mini = nums[k]; 6 while (left >= 0 || right < n) { 7 const int a = left >= 0 ? nums[left] : 0; 8 const int b = right < n ? nums[right] : 0; 9 mini = min(mini, a < b ? nums[right++] : nums[left--]); 10 res = max(res, mini * (right - left - 1)); 11 } 12 return res; 13 } 14 };