제출 #992171

#제출 시각아이디문제언어결과실행 시간메모리
992171sushikidKnapsack (NOI18_knapsack)Java
73 / 100
1049 ms36560 KiB
import java.util.*; import java.io.*; public class knapsack { public static void main(String[] args) throws IOException{ BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(r.readLine()); int s = Integer.parseInt(st.nextToken()); int n = Integer.parseInt(st.nextToken()); int[][] info = new int[n][3]; long ans = -1; long[] weight = new long[s + 1]; Arrays.fill(weight, Integer.MIN_VALUE); weight[0] = 0; for (int i = 0; i < n; i++) { st = new StringTokenizer(r.readLine()); info[i][0] = Integer.parseInt(st.nextToken()); info[i][1] = Integer.parseInt(st.nextToken()); info[i][2] = Math.min(s/info[i][1], Integer.parseInt(st.nextToken())); } for (int[] e : info) { for (int i = s; i >= e[1]; i--) { for (int j = Math.min(i/e[1], e[2]); j > 0; j--) { weight[i] = Math.max(weight[i], weight[i - j * e[1]] + e[0] * j); } } } for(long e : weight){ ans = Math.max(e, ans); } pw.println(ans); pw.close(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...