PDF Merger
Create several small PDF files (each with a given number of blank pages) and merge them into a single combined PDF, then report its total page count.
Why create the PDFs first? a judge sandbox has no pre-existing PDF files to merge, so the script builds its own simple ones first (using PdfWriter.addblankpage()), then merges them — testing the actual merge operation the notes cover, just without needing real report files handed to it.
Note on the library: the notes teach PyPDF2's PdfMerger; this uses pypdf (PyPDF2's actively-maintained successor — recent PyPDF2 releases are themselves just a thin wrapper around it) and PdfWriter.append(), which is the current recommended way to merge PDFs, since PdfMerger has been removed in modern pypdf versions.
Approach: build one small PDF per given page count, then append each into one combined PdfWriter, save it, and report the merged file's total page count.
Input: One line: space-separated page counts, one per PDF to create and merge.
Output: One line: Total pages: <sum of all page counts>.
2 3 1
Total pages: 6
- 1 <= number of PDFs <= 10
- 1 <= each page count <= 20
Hint 1
A fresh PdfWriter() can build the merged output — call .append(filename) once per file you want to add, in order.
Hint 2
merged_writer.write("combined_report.pdf") saves the merged result.
Hint 3
PdfReader("combined_report.pdf").pages gives you the final page list — its length is the total page count.
Each input page count becomes its own tiny PDF, built with PdfWriter.addblankpage(). Merging is then just calling .append(filename) on a fresh PdfWriter once per file, in order, and writing the result out — this is pypdf's modern replacement for the notes' PdfMerger, which newer pypdf releases have removed entirely. Reading the merged file back and counting len(reader.pages) confirms every page from every source file made it into the combined PDF.