Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.io.BufferedReader;
- import java.awt.Point;
- public class movie{
- public static final String TASKNAME = "movie";
- public static long mod= 1000000007;
- // public static Debug db;
- public static void main(String[] args) throws IOException {
- // InputReader in = new InputReader(System.in);
- // PrintWriter out = new PrintWriter(System.out);
- InputReader in = new InputReader(new FileInputStream(TASKNAME+".in"));
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(TASKNAME+".out")));
- Autocompletion solver = new Autocompletion();
- // db=new Debug(System.getSecurityManager()==null);
- solver.solve(1, in, out);
- out.close();
- }
- static class Autocompletion {
- public void solve(int testNumber, InputReader in, PrintWriter out) {
- int n=in.nextInt();
- int l=in.nextInt();
- int dur[]=new int[n];
- TreeSet<Integer>[] start=new TreeSet[n];;
- for(int i=0;i<n;i++) {
- dur[i]=in.nextInt();
- int c=in.nextInt();
- start[i]=new TreeSet<Integer>();
- for(int j=0;j<c;j++) {
- start[i].add(in.nextInt());
- }
- }
- int dp[]=new int[1<<n];
- for(int i=0;i<1<<n;i++) {
- for(int j=0;j<n;j++) {
- if((i& 1<<j)==0) {//movie not repeated
- if(start[j].contains(dp[i])) {//ends at start time
- dp[i|(1<<j)]=Math.max(dp[i|(1<<j)], dur[j]+dp[i]);
- }
- else if(start[j].lower(dp[i])!=null){
- dp[i|(1<<j)]=Math.max(dp[i|(1<<j)], dur[j]+start[j].lower(dp[i]));
- }
- }
- }
- }
- int ret=22;
- for(int i=0;i<dp.length;i++) {
- if(dp[i]>=l) {
- ret=Math.min(ret, Integer.bitCount(i));
- }
- }
- if(ret==22) {
- out.println(-1);
- }
- else {
- out.println(ret);
- }
- }
- }
- static class Pair implements Comparable<Pair>{
- int x;
- int y;
- Pair(int a, int b){
- x=a;
- y=b;
- }
- @Override
- public int compareTo(Pair arg0) {
- if(arg0.x!=x)return x-arg0.x;
- return y-arg0.y;
- }
- }
- static class Triple implements Comparable<Triple>{
- int x;
- int y;
- int z;
- Triple(int a, int b, int c){
- x=a;
- y=b;
- z=c;
- }
- @Override
- public int compareTo(Triple arg0) {
- if(arg0.x!=x)return x-arg0.x;
- return y-arg0.y;
- }
- }
- static class InputReader {
- public BufferedReader reader;
- public StringTokenizer tokenizer;
- public InputReader(InputStream stream) {
- reader = new BufferedReader(new InputStreamReader(stream), 32768);
- tokenizer = null;
- }
- public String next() {
- while (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- tokenizer = new StringTokenizer(reader.readLine());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return tokenizer.nextToken();
- }
- public int nextInt() {
- return Integer.parseInt(next());
- }
- public long nextLong() {
- return Long.parseLong(next());
- }
- public int[] nextIntArr(int n) {
- int arr[]=new int[n];
- for(int i=0;i<n;i++) {
- arr[i]=this.nextInt();
- }
- return arr;
- }
- }
- // public static class Debug {
- // private boolean allowDebug;
- //
- // public Debug(boolean allowDebug) {
- // this.allowDebug = allowDebug;
- // }
- //
- // private void outputName(String name) {
- // System.out.print(name + " = ");
- // }
- //
- // public void debug(String name, int x) {
- // if (!allowDebug) {
- // return;
- // }
- //
- // outputName(name);
- // System.out.println("" + x);
- // }
- //
- // public void debug(String name, long x) {
- // if (!allowDebug) {
- // return;
- // }
- // outputName(name);
- // System.out.println("" + x);
- // }
- //
- // public void debug(String name, double x) {
- // if (!allowDebug) {
- // return;
- // }
- // outputName(name);
- // System.out.println("" + x);
- // }
- //
- // public void debug(String name, int[] x) {
- // if (!allowDebug) {
- // return;
- // }
- // outputName(name);
- // System.out.println(Arrays.toString(x));
- // }
- //
- // public void debug(String name, long[] x) {
- // if (!allowDebug) {
- // return;
- // }
- // outputName(name);
- // System.out.println(Arrays.toString(x));
- // }
- //
- // public void debug(String name, double[] x) {
- // if (!allowDebug) {
- // return;
- // }
- // outputName(name);
- // System.out.println(Arrays.toString(x));
- // }
- //
- // public void debug(String name, Object x) {
- // if (!allowDebug) {
- // return;
- // }
- // outputName(name);
- // System.out.println("" + x);
- // }
- //
- // public void debug(String name, Object... x) {
- // if (!allowDebug) {
- // return;
- // }
- // outputName(name);
- // System.out.println(Arrays.deepToString(x));
- // }
- // }
- }
- //equal :problem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement