제출 #330107

#제출 시각아이디문제언어결과실행 시간메모리
330107AgnimandurJelly Flavours (IOI20_jelly)Java
100 / 100
319 ms13428 KiB
import java.util.*; class jelly { int find_maximum_unique(int x, int y, int[] a, int[] b) { int N = a.length; int[][] vals = new int[N][2]; for (int i = 0; i < N; i++) vals[i] = new int[] {a[i],b[i]}; sort(vals); long[] dpX = new long[x+1]; long[] budget = new long[N]; for (int i = 0; i < N; i++) { long[] dpXnew = new long[x+1]; for (int j = 0; j <= x; j++) { //buy in shop2 dpXnew[j] = dpX[j]+vals[i][1]; //buy in shop1 if (j >= vals[i][0]) dpXnew[j] = Math.min(dpXnew[j],dpX[j-vals[i][0]]); } dpX = dpXnew; budget[i] = y-dpX[x]; } int ans = 0; int[] dpY = new int[y+1]; for (int i = N-1; i >= 0; i--) { if (budget[i] >= 0) ans = Math.max(ans, i+1+dpY[(int)budget[i]]); int[] dpYnew = new int[y+1]; for (int j = 0; j <= y; j++) { //dont take this jelly dpYnew[j] = dpY[j]; //take this jelly if (j >= vals[i][1]) dpYnew[j] = Math.max(dpYnew[j], dpY[j-vals[i][1]]+1); } dpY = dpYnew; } ans = Math.max(ans, dpY[y]); return ans; } void sort(int[][] arr) { //Sort an array (immune to quicksort TLE) Random rgen = new Random(); for (int i = 0; i < arr.length; i++) { int randomPosition = rgen.nextInt(arr.length); int[] temp = arr[i]; arr[i] = arr[randomPosition]; arr[randomPosition] = temp; } Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(int[] arr1, int[] arr2) { return arr1[0]-arr2[0]; //Ascending order. } }); } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...