-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodingSpree.java
40 lines (35 loc) · 1.01 KB
/
codingSpree.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Class2;
import java.util.*;
/**
*
* @author EricaWang
*/
public class codingSpree {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
int t =input.nextInt();//num
int j = input.nextInt();//time
int [][] dp = new int [t+1][j+1];
for(int i = 1; i<=t; i++){
int value=input.nextInt();
int time=input.nextInt();
for(int u = 1; u<=j; u++){
if(time>u){
dp[i][u]=dp[i-1][u];
}else{
dp[i][u]=Math.max(value+dp[i-1][u-time],dp[i-1][u]);
}
}
}
System.out.println(dp[t][j]);
}
}