-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp5215.java
62 lines (51 loc) · 1.58 KB
/
p5215.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package self.samsungExpert;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
// platform | SWEA
// number | 5215
// title | 햄버거 다이어트
// level | D3
// how |
// etc |
// result |
public class p5215 {
static int N, L;
static int[] score;
static int[] cal;
static int ans;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for(int t=1; t<=T; t++) {
st = new StringTokenizer(br.readLine(), " ");
N = Integer.parseInt(st.nextToken());
L = Integer.parseInt(st.nextToken());
score = new int[N+1];
cal = new int[N+1];
for(int i=0; i<N; i++) {
st = new StringTokenizer(br.readLine(), " ");
score[i] = Integer.parseInt(st.nextToken());
cal[i] = Integer.parseInt(st.nextToken());
}
// 초기화 해야함.
ans = 0;
hamburger(0, 0, 0);
System.out.println("#" + t + " " + ans);
}
}
static void hamburger(int idx, int sumt, int sumc) {
if (sumc > L)
return;
if (idx == N) {
if (sumt > ans) {
ans = sumt;
}
return;
}
hamburger(idx + 1, sumt + score[idx], sumc + cal[idx]);
hamburger(idx + 1, sumt, sumc);
}
}