Choose one buffer size K for all files to minimize sum over files of ceil(F_i/K) times (T+K).
Hard8MathNumber theoryBrute forceImplementationNo attempts yetTime limit1sMemory limit512 MBOperating systems in the Unix family provide a system call named read() for reading files. When passed a buffer of K bytes, read() loads file contents into that buffer, and one call takes (T+K) time, where T is the fixed per-call overhead. The running time depends only on the buffer size, never on how many bytes are actually read. For example, with a 10-byte buffer, reading 3 bytes and reading 7 bytes both take (T+10) time.
Reading a single file of F bytes therefore needs ⌈F/K⌉ calls. The total time to read all of N files with sizes F1,F2,…,FN bytes is
∑i=1N⌈Fi/K⌉×(T+K)
Mingyu decided to use one fixed buffer size K for every file, where K is a positive integer. Find the buffer size K that minimizes the total reading time.
The first line contains the number of files N. The second line contains N positive integers Fi, the file sizes in bytes. The third line contains the fixed per-call time T, a nonnegative integer.
Print the shortest achievable total reading time and the buffer size K attaining it, separated by a space. If several buffer sizes achieve the shortest time, print the smallest such K.
Linux is a representative Unix-family operating system. macOS also belongs to the Unix family, along with FreeBSD, NetBSD, Solaris, and others.