Advertisement
ec1117

Untitled

Jun 24th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.io.BufferedReader;
  4. import java.awt.Point;
  5.  
  6. public class movie{
  7. public static final String TASKNAME = "movie";
  8. public static long mod= 1000000007;
  9. // public static Debug db;
  10.  
  11. public static void main(String[] args) throws IOException {
  12. // InputReader in = new InputReader(System.in);
  13. // PrintWriter out = new PrintWriter(System.out);
  14. InputReader in = new InputReader(new FileInputStream(TASKNAME+".in"));
  15. PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(TASKNAME+".out")));
  16. Autocompletion solver = new Autocompletion();
  17. // db=new Debug(System.getSecurityManager()==null);
  18. solver.solve(1, in, out);
  19. out.close();
  20. }
  21. static class Autocompletion {
  22.  
  23. public void solve(int testNumber, InputReader in, PrintWriter out) {
  24. int n=in.nextInt();
  25. int l=in.nextInt();
  26. int dur[]=new int[n];
  27. TreeSet<Integer>[] start=new TreeSet[n];;
  28. for(int i=0;i<n;i++) {
  29. dur[i]=in.nextInt();
  30. int c=in.nextInt();
  31. start[i]=new TreeSet<Integer>();
  32. for(int j=0;j<c;j++) {
  33. start[i].add(in.nextInt());
  34. }
  35. }
  36. int dp[]=new int[1<<n];
  37. for(int i=0;i<1<<n;i++) {
  38. for(int j=0;j<n;j++) {
  39. if((i& 1<<j)==0) {//movie not repeated
  40. if(start[j].contains(dp[i])) {//ends at start time
  41. dp[i|(1<<j)]=Math.max(dp[i|(1<<j)], dur[j]+dp[i]);
  42. }
  43. else if(start[j].lower(dp[i])!=null){
  44. dp[i|(1<<j)]=Math.max(dp[i|(1<<j)], dur[j]+start[j].lower(dp[i]));
  45. }
  46. }
  47. }
  48. }
  49. int ret=22;
  50. for(int i=0;i<dp.length;i++) {
  51. if(dp[i]>=l) {
  52. ret=Math.min(ret, Integer.bitCount(i));
  53. }
  54. }
  55. if(ret==22) {
  56. out.println(-1);
  57. }
  58. else {
  59. out.println(ret);
  60. }
  61. }
  62. }
  63. static class Pair implements Comparable<Pair>{
  64. int x;
  65. int y;
  66. Pair(int a, int b){
  67. x=a;
  68. y=b;
  69. }
  70. @Override
  71. public int compareTo(Pair arg0) {
  72. if(arg0.x!=x)return x-arg0.x;
  73. return y-arg0.y;
  74. }
  75. }
  76. static class Triple implements Comparable<Triple>{
  77. int x;
  78. int y;
  79. int z;
  80. Triple(int a, int b, int c){
  81. x=a;
  82. y=b;
  83. z=c;
  84. }
  85. @Override
  86. public int compareTo(Triple arg0) {
  87. if(arg0.x!=x)return x-arg0.x;
  88. return y-arg0.y;
  89. }
  90. }
  91.  
  92. static class InputReader {
  93. public BufferedReader reader;
  94. public StringTokenizer tokenizer;
  95.  
  96. public InputReader(InputStream stream) {
  97. reader = new BufferedReader(new InputStreamReader(stream), 32768);
  98. tokenizer = null;
  99. }
  100.  
  101. public String next() {
  102. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  103. try {
  104. tokenizer = new StringTokenizer(reader.readLine());
  105. } catch (IOException e) {
  106. throw new RuntimeException(e);
  107. }
  108. }
  109. return tokenizer.nextToken();
  110. }
  111.  
  112. public int nextInt() {
  113. return Integer.parseInt(next());
  114. }
  115. public long nextLong() {
  116. return Long.parseLong(next());
  117. }
  118. public int[] nextIntArr(int n) {
  119. int arr[]=new int[n];
  120. for(int i=0;i<n;i++) {
  121. arr[i]=this.nextInt();
  122. }
  123. return arr;
  124. }
  125. }
  126. // public static class Debug {
  127. // private boolean allowDebug;
  128. //
  129. // public Debug(boolean allowDebug) {
  130. // this.allowDebug = allowDebug;
  131. // }
  132. //
  133. // private void outputName(String name) {
  134. // System.out.print(name + " = ");
  135. // }
  136. //
  137. // public void debug(String name, int x) {
  138. // if (!allowDebug) {
  139. // return;
  140. // }
  141. //
  142. // outputName(name);
  143. // System.out.println("" + x);
  144. // }
  145. //
  146. // public void debug(String name, long x) {
  147. // if (!allowDebug) {
  148. // return;
  149. // }
  150. // outputName(name);
  151. // System.out.println("" + x);
  152. // }
  153. //
  154. // public void debug(String name, double x) {
  155. // if (!allowDebug) {
  156. // return;
  157. // }
  158. // outputName(name);
  159. // System.out.println("" + x);
  160. // }
  161. //
  162. // public void debug(String name, int[] x) {
  163. // if (!allowDebug) {
  164. // return;
  165. // }
  166. // outputName(name);
  167. // System.out.println(Arrays.toString(x));
  168. // }
  169. //
  170. // public void debug(String name, long[] x) {
  171. // if (!allowDebug) {
  172. // return;
  173. // }
  174. // outputName(name);
  175. // System.out.println(Arrays.toString(x));
  176. // }
  177. //
  178. // public void debug(String name, double[] x) {
  179. // if (!allowDebug) {
  180. // return;
  181. // }
  182. // outputName(name);
  183. // System.out.println(Arrays.toString(x));
  184. // }
  185. //
  186. // public void debug(String name, Object x) {
  187. // if (!allowDebug) {
  188. // return;
  189. // }
  190. // outputName(name);
  191. // System.out.println("" + x);
  192. // }
  193. //
  194. // public void debug(String name, Object... x) {
  195. // if (!allowDebug) {
  196. // return;
  197. // }
  198. // outputName(name);
  199. // System.out.println(Arrays.deepToString(x));
  200. // }
  201. // }
  202. }
  203.  
  204. //equal :problem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement