Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws Exception
- {
- String fileOut = file + "out";
- PrintWriter w = new PrintWriter(new FileWriter(fileOut));
- int _k = Integer.valueOf("1");
- if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
- else in = new BufferedReader(new FileReader(file));
- if(test < 0) {String[] str = in.readLine().split(" ");}
- /***********************************************************************/
- /***********************************************************************/
- /***********************************************************************/
- /***********************************************************************/
- // System.out.println((-100 + 0) / 2);
- int[] ary = toIntArray();
- int B = ary[0];
- int L = ary[1];
- int D = ary[2];
- int[] books = toIntArray();
- int[] numberOfBooksInLibrary = new int[L];
- int[] numberOfDaysToSignup = new int[L];
- int[] speedOfBooksScanned = new int[L];
- List<List<Integer>> booksInLibrary = new ArrayList<>();
- for (int i = 0; i < L; i++) {
- ary = toIntArray();
- numberOfBooksInLibrary[i] = ary[0];
- numberOfDaysToSignup[i] = ary[1];
- speedOfBooksScanned[i] = ary[2];
- booksInLibrary.add(new ArrayList<>());
- ary = toIntArray();
- for (int j = 0; j < numberOfBooksInLibrary[i]; j++) {
- booksInLibrary.get(i).add(ary[j]);
- }
- }
- PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {
- @Override
- public int compare(Integer o1, Integer o2) {
- return numberOfDaysToSignup[o1] - numberOfDaysToSignup[o2];
- }
- });
- int l = L;
- for (int i = 0; i < L; i++)
- {
- pq.offer(i);
- }
- // System.out.println(pq);
- for (List<Integer> list : booksInLibrary) {
- Collections.sort(list, new Comparator<Integer>() {
- @Override
- public int compare(Integer o1, Integer o2) {
- return books[o2] - books[o1];
- }
- });
- }
- //record books in the lib scan order
- List<Integer>[] res = new ArrayList[l];
- //current index
- int[] index = new int[l];
- //the library is being processed
- List<Integer> libQueue = new ArrayList<>();
- for (int i = 0; i < l; i++) {
- res[i] = new ArrayList<>();
- }
- int lib = pq.poll();
- int nextLibTime = numberOfDaysToSignup[lib] - 1;
- Set<Integer> scannedBooks = new HashSet<>();
- int totalLibraries = 0;
- // System.out.println(booksInLibrary);
- for(int i = 0; i < D; i++)
- {
- if(nextLibTime == 0)
- {
- if(pq.isEmpty()) break;
- totalLibraries++;
- // System.out.println(pq);
- int nextLib = pq.poll();
- libQueue.add(lib);
- for(int nextBook : booksInLibrary.get(lib))
- {
- if(scannedBooks.contains(nextBook)) continue;
- scannedBooks.add(nextBook);
- res[lib].add(nextBook);
- }
- lib = nextLib;
- nextLibTime = numberOfDaysToSignup[lib] - 1;
- }
- else nextLibTime--;
- }
- w.println(totalLibraries);
- for(int i : libQueue)
- {
- w.printf("%d %d\n", i, res[i].size());
- for (int book : res[i])
- {
- w.printf("%d ", book);
- }
- w.printf("\n");
- }
- w.flush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement