1937.cpp (835B)
1 class Solution { 2 public: 3 long long maxPoints(vector<vector<int>> &points) const { 4 const int n = size(points), m = size(points[0]); 5 static long long crnt[100001], left[100001], right[100001]; 6 7 for (int j = 0; j < m; j++) 8 crnt[j] = points[0][j]; 9 for (int i = 1; i < n; i++) { 10 11 left[0] = crnt[0]; 12 for (int j = 1; j < m; j++) { 13 left[j] = max(left[j - 1], crnt[j] + j); 14 } 15 16 right[m - 1] = crnt[m - 1] - (m - 1); 17 for (int j = m - 2; j >= 0; j--) { 18 right[j] = max(right[j + 1], crnt[j] - j); 19 } 20 21 for (int j = 0; j < m; j++) { 22 crnt[j] = points[i][j] + max(left[j] - j, right[j] + j); 23 } 24 } 25 26 return *max_element(crnt, crnt + m); 27 } 28 };