-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB14501_1.java
More file actions
47 lines (37 loc) · 973 Bytes
/
B14501_1.java
File metadata and controls
47 lines (37 loc) · 973 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
43
44
45
46
47
package Practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B14501_1 { //Åð»ç(¹éÆ®·¡Å·)
static int N, temp, max;
static int[] T, P;
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
T = new int[N];
P = new int[N];
for(int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
T[i] = Integer.parseInt(st.nextToken());
P[i] = Integer.parseInt(st.nextToken());
}
max = 0;
Solve(0);
System.out.println(max);
}
public static void Solve(int index) {
if(index >= N) {
max = Math.max(max, temp);
return;
}
for(int i = index; i < N; i++) {
if(i + T[i] <= N) {
temp += P[i];
Solve(i + T[i]);
temp -= P[i];
}
}
max = Math.max(max, temp);
}
}