Submission #513157
Source Code Expand
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in),1);
String[]s=getLine(r).split(" ");
int N=Integer.parseInt(s[0]);
int T=Integer.parseInt(s[1]);
int[]A=new int[N],B=new int[N];
int x=0,y=0;
for(int i=0;i<N;i++){
s=getLine(r).split(" ");
A[i]=Integer.parseInt(s[0]);
B[i]=Integer.parseInt(s[1]);
x+=A[i];
y+=B[i];
}
if(x<=T){
System.out.println(0);
}else if(y>T){
System.out.println(-1);
}else if(y==T){
System.out.println(N);
}else {
HashMap<Integer,Integer>xx=new HashMap<Integer,Integer>();
System.out.println(rec(A,B,N,T,0,0,0,xx));
}
}
//num=配列番号、rec=Bの数
static int rec(int[]A,int[]B,int N,int T,int time,int num,int rec,HashMap<Integer,Integer>list){
if(N==num){
return rec;
}
else if(list.containsKey(num*T+time)){
return list.get(num*T+time);
}
int x=Integer.MAX_VALUE,y=Integer.MAX_VALUE;
if(T>=time+A[num])
x=rec(A,B,N,T,time+A[num],num+1,rec,list);//A+
if(T>=time+B[num])
y=rec(A,B,N,T,time+B[num],num+1,rec+1,list);//B
int min=Math.min(x, y);
if(list.containsKey(num*T+time)){
if(min<list.get(num*T+time)){
list.put(num*T+time, min);
}
}else {
list.put(num*T+time, min);
}
return min;
}
static String getLine(BufferedReader r){
try {
return r.readLine();
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
return null;
}
}
Submission Info
| Submission Time |
|
| Task |
C - 8月31日 |
| User |
sky02468 |
| Language |
Java (OpenJDK 1.7.0) |
| Score |
0 |
| Code Size |
1784 Byte |
| Status |
TLE |
| Exec Time |
2536 ms |
| Memory |
247436 KiB |
Judge Result
| Set Name |
Sample |
Dataset1 |
Dataset2 |
| Score / Max Score |
0 / 0 |
0 / 30 |
0 / 70 |
| Status |
|
|
|
| Set Name |
Test Cases |
| Sample |
sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
| Dataset1 |
sample-01, sample-02, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt |
| Dataset2 |
sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01-01.txt |
AC |
356 ms |
22376 KiB |
| 01-02.txt |
AC |
357 ms |
22412 KiB |
| 01-03.txt |
AC |
355 ms |
22412 KiB |
| 01-04.txt |
TLE |
2194 ms |
140212 KiB |
| 01-05.txt |
TLE |
2067 ms |
136960 KiB |
| 01-06.txt |
TLE |
2256 ms |
224500 KiB |
| 01-07.txt |
TLE |
2061 ms |
61216 KiB |
| 01-08.txt |
TLE |
2255 ms |
199224 KiB |
| 01-09.txt |
TLE |
2536 ms |
154536 KiB |
| 01-10.txt |
TLE |
2051 ms |
150500 KiB |
| 01-11.txt |
AC |
879 ms |
38432 KiB |
| 01-12.txt |
AC |
919 ms |
38260 KiB |
| 01-13.txt |
AC |
845 ms |
38124 KiB |
| 01-14.txt |
TLE |
2044 ms |
61192 KiB |
| 01-15.txt |
TLE |
2093 ms |
212388 KiB |
| 02-01.txt |
AC |
348 ms |
22376 KiB |
| 02-02.txt |
AC |
386 ms |
22212 KiB |
| 02-03.txt |
AC |
363 ms |
22488 KiB |
| 02-04.txt |
TLE |
2049 ms |
131512 KiB |
| 02-05.txt |
TLE |
2081 ms |
148036 KiB |
| 02-06.txt |
TLE |
2294 ms |
247436 KiB |
| 02-07.txt |
TLE |
2277 ms |
221992 KiB |
| 02-08.txt |
TLE |
2059 ms |
235724 KiB |
| 02-09.txt |
TLE |
2291 ms |
215144 KiB |
| 02-10.txt |
TLE |
2221 ms |
188484 KiB |
| 02-11.txt |
TLE |
2252 ms |
129400 KiB |
| 02-12.txt |
AC |
849 ms |
38152 KiB |
| 02-13.txt |
AC |
938 ms |
38820 KiB |
| 02-14.txt |
TLE |
2092 ms |
243072 KiB |
| 02-15.txt |
TLE |
2285 ms |
217164 KiB |
| 02-16.txt |
TLE |
2127 ms |
205024 KiB |
| sample-01.txt |
AC |
345 ms |
22404 KiB |
| sample-02.txt |
AC |
344 ms |
22380 KiB |
| sample-03.txt |
AC |
345 ms |
22308 KiB |
| sample-04.txt |
AC |
344 ms |
22380 KiB |
| sample-05.txt |
AC |
344 ms |
22376 KiB |