-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskii.cpp
More file actions
36 lines (32 loc) · 872 Bytes
/
skii.cpp
File metadata and controls
36 lines (32 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int maxScore(vector<int> heights, vector<int> scores, int K) {
int N = heights.size();
vector<int> dp(N, 0);
dp[0] = scores[0];
for (int i = 1; i < N; i++) {
int maxPrevScore = 0;
for (int j = 0; j < i; j++) {
if (heights[j] - heights[i] <= K && heights[j] >= heights[i]) {
maxPrevScore = max(maxPrevScore, dp[j]);
}
}
dp[i] = scores[i] + maxPrevScore;
}
return *max_element(dp.begin(), dp.end());
}
int main() {
int N, K;
cin >> N >> K;
vector<int> heights(N);
vector<int> scores(N);
for (int i = 0; i < N; i++) {
cin >> heights[i] >> scores[i];
}
int result = maxScore(heights, scores, K);
cout << result << endl;
return 0;
}