text: // Hi, I'm Yanzhan. I'm interested in all kinds of algorithmic problems. Also, I'm fascinated with javascript. If you want to learn more about programming problems and javascript, please visit my Youtube Channel (https://www.youtube.com/channel/UCDkz-__gl3frqLexukpG0DA?view_as=subscriber), Twitter Account (https://twitter.com/YangYanzhan), GitHub Repo (https://github.com/yangyanzhan/code-camp) or HomePage (https://yanzhan.site/).
  
  // 开始分析
  // 1. 记录右侧最大值。
  // 结束分析
  
  // 开始编码
  
  /**
   * @param {number[]} values
   * @return {number}
   */
  
  var maxScoreSightseeingPair = function(values) {
      var n = values.length;
      if (n <= 1) {
          return 0;
      }
      var res = Number.NEGATIVE_INFINITY;
      var cache = [], pre = Number.NEGATIVE_INFINITY;
      for (var i = values.length - 1; i > 0; i--) {
          cache.push(Math.max(pre, values[i] - i));
          pre = cache[cache.length - 1];
      }
      cache.reverse();
      var cnt = 0;
      for (var i = 0; i < values.length - 1; i++) {
          var sum = values[i] + cache[i] + cnt;
          res = Math.max(res, sum);
          cnt++;
      }
      return res;
  };
  