Practice for Microsoft 2015 Online Test register

Ended

Participants:1406

Verdict:Accepted
Score:100 / 100
Submitted:2014-10-18 12:29:23

Lang:Java

Edit
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
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        int n = in.nextInt(), m = in.nextInt();
        int[] need = new int[n], value = new int[n];
        for (int i = 0i < ni++) {
            need[i= in.nextInt();
            value[i= in.nextInt();
        }
        int[] dp = new int[m + 1];
        for (int i = 0i < ni++) {
            for (int j = mj > 0j--) {
                dp[j= Math.max(dp[j], j >= need[i] ? dp[j - need[i]]
                        + value[i] : 0);
            }
        }
        System.out.println(dp[m]);
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX