electicode
HomeCoursesResourcesProblemsNational OlympiadContestsLeaderboard
...

Book and Stamps

Time Limit: 1000msMemory Limit: 256MB
View Submissions

Problem Description

In the Royal Library, archivists write magic books. To complete the next book, the iii-th letter must be used at least C[i]C[i]C[i] times. Remember that the country uses an alphabet of nnn letters.

A stamp is a piece of sticky paper with mmm letters written on it (letters may repeat). The appearance of the stamp, which letters are written on it, etc., is agreed upon in advance and cannot be changed. After agreeing on the appearance of the stamp, based on this agreement an unlimited number of stamps will be created.

The book will be printed using these stamps. Only one stamp may be affixed to one page of the book.

If you can choose mmm letters for the stamp design, find the minimum number of pages needed to write the book.

If it is impossible to write the book, i.e. even an unlimited number of stamps will not be enough, then output −1-1−1.

Input Format

The first line gives nnn --- the number of letters in the alphabet and mmm --- the number of letters in the stamp.

The second line gives nnn integers C[i]C[i]C[i] --- the minimum required number of the iii-th letter to write the book.

Constraints:

  • 1≤n≤200 0001 \leq n \leq 200\,0001≤n≤200000
  • 0≤m≤10180 \leq m \leq 10^{18}0≤m≤1018
  • 0≤C[i]≤1090 \leq C[i] \leq 10^90

Output Format

Output the minimum number of pages to write the book, given that you are designing the stamp. If this is impossible, output −1-1−1.

Scoring

SubtaskAdditional constraintsPointsRequired subtasks
000Tests from the example000-
111n≤20n \leq 20n≤;

Notes

In the first test, no matter how many stamps there are, it is impossible to make 333 different letters from a stamp that holds 222 symbols.

© 2026 Electicode. All rights reserved.

≤
C[i]≤
109
20
C[i]≤20C[i] \leq 20C[i]≤20
202020
000
222n≤1000n \leq 1000n≤1000; C[i]≤100C[i] \leq 100C[i]≤100101010000, 111
333n≤1000n \leq 1000n≤1000303030000, 111, 222
444No additional constraints404040000, 111, 222, 333