|
| 1 | +```java |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +import java.io.*; |
| 5 | + |
| 6 | +class Main { |
| 7 | + |
| 8 | + // IO field |
| 9 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 10 | + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 11 | + static StringTokenizer st = new StringTokenizer(""); |
| 12 | + |
| 13 | + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} |
| 14 | + static String nextToken() throws Exception { |
| 15 | + while(!st.hasMoreTokens()) nextLine(); |
| 16 | + return st.nextToken(); |
| 17 | + } |
| 18 | + static int nextInt() throws Exception { return Integer.parseInt(nextToken()); } |
| 19 | + static long nextLong() throws Exception { return Long.parseLong(nextToken()); } |
| 20 | + static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } |
| 21 | + static void bwEnd() throws Exception {bw.flush();bw.close();} |
| 22 | + |
| 23 | + // Additional field |
| 24 | + |
| 25 | + static int N, X, Y; |
| 26 | + static int[] x, y; |
| 27 | + static int[][] max, rec; |
| 28 | + |
| 29 | + static final int INF = -123456; |
| 30 | + |
| 31 | + public static void main(String[] args) throws Exception { |
| 32 | + |
| 33 | + ready(); |
| 34 | + solve(); |
| 35 | + |
| 36 | + bwEnd(); |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + static void ready() throws Exception{ |
| 41 | + |
| 42 | + N = nextInt(); |
| 43 | + X = nextInt(); |
| 44 | + Y = nextInt(); |
| 45 | + x = new int[N]; |
| 46 | + y = new int[N]; |
| 47 | + for(int i=0;i<N;i++) { |
| 48 | + x[i] = nextInt(); |
| 49 | + y[i] = nextInt(); |
| 50 | + } |
| 51 | + max = new int[5001][51]; |
| 52 | + rec = new int[5001][51]; |
| 53 | + for(int i=0;i<=5000;i++) { |
| 54 | + Arrays.fill(max[i], INF); |
| 55 | + Arrays.fill(rec[i], INF); |
| 56 | + } |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + static void solve() throws Exception{ |
| 61 | + |
| 62 | + max[0][0] = 0; |
| 63 | + for(int i=0;i<N;i++) { |
| 64 | + for(int c=i+1;c>0;c--) for(int j=100*(i+1);j>=x[i];j--) if(max[j-x[i]][c-1] != INF) { |
| 65 | + if(max[j][c] < Y && max[j-x[i]][c-1] + y[i] >= Y) { |
| 66 | + rec[j][c] = i+1; |
| 67 | + } |
| 68 | + max[j][c] = Math.max(max[j][c], max[j-x[i]][c-1] + y[i]); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + for(int c=1;c<=N;c++) { |
| 73 | + boolean find = false; |
| 74 | + int min = -INF; |
| 75 | + for(int i=X;i<=5000;i++) if(max[i][c] >= Y) { |
| 76 | + find = true; |
| 77 | + min = Math.min(min, rec[i][c]); |
| 78 | + } |
| 79 | + if(find) { |
| 80 | + bw.write(c + "\n" + min); |
| 81 | + return; |
| 82 | + } |
| 83 | + } |
| 84 | + bw.write("-1"); |
| 85 | + |
| 86 | + } |
| 87 | + |
| 88 | +} |
| 89 | + |
| 90 | +``` |
0 commit comments