-
Notifications
You must be signed in to change notification settings - Fork 0
/
P14585.cpp
42 lines (33 loc) · 991 Bytes
/
P14585.cpp
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
37
38
39
40
41
42
#include <iostream>
using namespace std;
int candy[302][302] = {};
int dp[302][302] = {};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
candy[a][b] = 1;
}
for (int i = 0; i < 301; i++) {
for (int j = 0; j < 301; j++) {
if (i == 0 && j == 0) continue;
if (i == 0) {
if (candy[i][j]) dp[i][j] = dp[i][j - 1] + (M - i - j);
else dp[i][j] = dp[i][j - 1];
} else if (j == 0) {
if (candy[i][j]) dp[i][j] = dp[i - 1][j] + (M - i - j);
else dp[i][j] = dp[i - 1][j];
} else {
if (candy[i][j]) dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + (M - i - j);
else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
cout << dp[300][300];
return 0;
}