bouquets

Time limit: 1.8s Memory limit: 256MB Input: Output:

A flower shop has an unlimited quantity of flowers of NN types, each having respectively a1,a2,..,aNa_1, a_2, .., a_N petals. A corporate client has made MM orders at the shop. Each order has the following requirements:

  • KK different bouquets must be made, each containing the same number of flowers (two bouquets are considered different if there is a difference in the types of flowers used);
  • Only flowers having at least LL and at most RR petals may be used;
  • Each bouquet may contain at most one flower of each type.

The florists want to use as few flowers as possible. Help them by writing the program bouquets that determines the minimum number of flowers each bouquet can contain for every order so that the given requirements are satisfied.

Input data

The first line of the standard input contains the positive integers NN and MM, representing respectively the number of different types of flowers and the number of orders. The next line contains NN positive integers a1,a2,...,aNa_1,a_2,...,a_N, indicating the number of petals for each type of flower. Each of the following MM lines contains three positive integers LL, RR, and KK, describing each order.

Output data

For each order, print the requested number of flowers on a separate line. If a given order cannot be fulfilled, output 1-1 for it.

Restrictions

  • 1N3 0001 \leq N \leq 3 \ 000
  • 1M1051 \leq M \leq 10^5
  • 1ai1051 \leq a_i \leq 10^5
  • 1LR1051 \leq L \leq R \leq 10^5
  • 1K109001 \leq K \leq 10^{900}
Subtask Points Required subtasks NN KK Other constraints
0 0 - - - The sample test.
1 11 00 15\leq 15 250\leq 250 -
2 13 010-1 50\leq 50 1018\leq 10^{18} -
3 15 020-2 100\leq 100 10900\leq 10^{900} -
4 19 030-3 1 500\leq 1 \ 500 10900\leq 10^{900} M104M \leq 10^4
5 20 040-4 1 600\leq 1 \ 600 10900\leq 10^{900} -
6 5 - 3 000\leq 3 \ 000 =1= 1 -
7 17 060-6 3 000\leq 3 \ 000 10900\leq 10^{900} -

Example

stdin

7 3
3 4 1 1 6 1 2
2 5 3
4 7 3
1 2 5

stdout

1
-1
2

Explanation

For the first order, the flowers of type 11, 22 and 77 can be used (with 33, 44 and 22 petals accordingly). If each bouquet contains one flower, exactly 33 different bouquets can be made.
For the second order, the flowers of type 22 and 55 can be used (with 44 and 66 petals accordingly). Thus, it is not possible to make 33 different bouquets. For the third order, a total of 44 types of flowers can be used. If each bouquet contains 22 flowers, at least 55 different bouquets can be made.

Log in or sign up to be able to send submissions!