Թաքցված խնդիր
|Այս խնդիրը թաքցված է խմբագրական խրհրդի անդամի կողմից քանի որ կամ այն ոչ ճիշտ լեզվով է գրված,|կամ թեստային տվյալներն են սխալ, կամ խնդրի ձևակերպումը պարզ չէ։|

ACM_0216 - KOLONIE

   An important task of the hyper-cosmic spaceship Nostromo is to establish a permanent base on the orbit of the planet MX8-26B in the Centaurus constellation. The base is built from complexes composed of identical hexagonal cubicles. Each of the six sides of each cubicle contains a hole serving either as a passage to a neighboring cubicle or as a window in case when no cubicle of the finished base is neighboring at this side. The complexes can be composed of the cubicles in many different ways.

   The travelers have a given number of complexes of several shapes at their disposition. Every cubicle in the finished base accommodates as many people as the number of windows it has.

   Write a program to determine whether it is possible to build a base for the prescribed number of people given the descriptions of available complexes.

Input

   The first line of the input contains the number of test cases N . The first line of each test case contains two space-separated positive integers P 1 000 000 and T 1000, where P is the number of inhabitants for whom the base is to be built and T is the number of shapes of available complexes.

   Each of the following T lines contains integers separated by spaces describing one shape of a complex. The first two numbers  on each of these lines are integers C and S, where C (0 C 1000) is the number of available complexes of this shape and S (1 S 1000) is the number of cubicles that make up the complex. It is known that every complex is connected and the hexagonal bottom bases of its cubicles lie in one plane.

Output

   For each test case, print exactly one line. If it is possible to build the base, the line says “Je treba X celku.”, where X is the minimal possible number of complexes when the shapes and their connections are chosen optimally. Otherwise print “Kapacita zakladny je pouze X lidi.”, where X is the maximal number of people that can fit inside the optimal base built from all of the available complexes.

Examples

stdin

stdout

1

3
50 5
10 1 0 0
3 4 0 0 1 0 2 0 2 1
4 5 0 0 0 1 0 2 1 1 2 0
6 6 0 0 1 0 2 0 0 1 1 1 0 2
1 7 1 0 2 0 0 1 1 1 2 1 0 2 1 2
11 1
2 1 0 0
10 2
100 1 1 1
0 2 0 0 1 0

Je treba 3 celku.
Kapacita zakladny je pouze 10 lidi.
Je treba 2 celku.


Ավելացրեց.Հրանտ Հովհաննիսյան
Ամսաթիվ.2014-10-08
Ժամանակի սահմանափակումը.1s
Ծրագրի տեքստի սահմանափակումը.50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Լեզուներ.Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE
Աղբյուրը.CTU Open 2014.A

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.