This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.util.Arrays;
import java.util.Scanner;
class DayOne {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int maxWeight = in.nextInt();
int numItems = in.nextInt();
int[] values = new int[numItems];
int[] weights = new int[numItems];
int[] quantities = new int[numItems];
for(int i = 0; i < numItems; ++i) {
values[i] = in.nextInt();
weights[i] = in.nextInt();
quantities[i] = in.nextInt();
}
int[] maxValueGivenWeight = new int[maxWeight + 1];
for(int i = 0; i < numItems; ++i) {
for(int q = 0; q < quantities[i]; ++q) {
// consider the subset of items from 0..i
for(int curWeight = maxWeight; curWeight >= 0; --curWeight) {
if(weights[i] <= curWeight) {
maxValueGivenWeight[curWeight] = Math.max(
maxValueGivenWeight[curWeight],
values[i] + maxValueGivenWeight[curWeight - weights[i]]
);
}
}
}
}
System.out.println(maxValueGivenWeight[maxWeight]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |