-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGravyJobs_011.java
More file actions
42 lines (33 loc) · 906 Bytes
/
GravyJobs_011.java
File metadata and controls
42 lines (33 loc) · 906 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
37
38
39
40
41
42
package java;
import java.util.*;
/**
* 011 - Gravy Jobs(★6)
* DP法
* 締め切りが早い順
*/
public class GravyJobs_011 {
private static int N;
private static int[][] DCS;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
DCS = new int[N][3];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
DCS[i][j] = sc.nextInt();
}
}
Arrays.sort(DCS, (a, b) -> a[0] - b[0]);
int lastD = DCS[N - 1][0];
long[] dp = new long[lastD + 1];
for (int i = 0; i < N; i++) {
for (int j = DCS[i][0]; j >= DCS[i][1]; j--) {
dp[j] = Math.max(dp[j], dp[j - DCS[i][1]] + DCS[i][2]);
}
}
// 仕事iをする場合としない場合のうち最大値を取る
long ans = Arrays.stream(dp).max().getAsLong();
System.out.println(ans);
sc.close();
}
}