You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #139 on September 15, 2026 11:12.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/maximum-number-of-points-with-cost/
Problem Summary
2차원에서 점수를 먹는 문제. 먹을 때 이전에 먹은 열과 비교해서 그 차이만큼은 빼야 한다.
Solution
3차원 dp는 쉽다. 다만 시간 초과.
2차원으로 어떻게 하면 줄일 수 있을까?
왼쪽에서 왔을 때의 최대와 오른쪽에서 왔을 때의 최대를 같이 구해서 그 중 최대값으로 업데이트하면 된다.
에디토리얼 참고.
간단하게 설명하면 left_max[i]는 i보다 왼쪽의 점수 중에 최대, right_max[i]는 i보다 오른쪽의 점수 중에 최대로 하고 거리에 따라 점수를 보정한다고 생각하면 된다.
이렇게 하면 시간복잡도는 O(m*n)
Source Code
All reactions