Skip to content

Commit bb39b17

Browse files
authored
Create: 2140-solving-questions-with-brainpower.c
1 parent 38d4fc8 commit bb39b17

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
long long mostPoints(int** questions, int questionsSize, int* questionsColSize) {
2+
int n = questionsSize;
3+
long long* dp = (long long*)malloc((n + 1) * sizeof(long long));
4+
5+
for (int i = 0; i <= n; i++) {
6+
dp[i] = 0;
7+
}
8+
9+
for (int i = n - 1; i >= 0; i--) {
10+
int points = questions[i][0];
11+
int jump = questions[i][1];
12+
dp[i] = (points + dp[(jump + i + 1) < n ? (jump + i + 1) : n]) > dp[i + 1] ? (points + dp[(jump + i + 1) < n ? (jump + i + 1) : n]) : dp[i + 1];
13+
}
14+
15+
long long result = dp[0];
16+
free(dp);
17+
return result;
18+
}

0 commit comments

Comments
 (0)