CF10B.Cinema Cashier

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

All cinema halls in Berland are rectangles with KK rows of KK seats each, and KK is an odd number. Rows and seats are numbered from 11 to KK . For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the responsibility of a special seating program. It was found out that the large majority of Berland's inhabitants go to the cinema in order to watch a movie, that's why they want to sit as close to the hall center as possible. Moreover, a company of MM people, who come to watch a movie, want necessarily to occupy MM successive seats in one row. Let's formulate the algorithm, according to which the program chooses seats and sells tickets. As the request for MM seats comes, the program should determine the row number xx and the segment [yl,yr][y_{l},y_{r}] of the seats numbers in this row, where yryl+1=My_{r}-y_{l}+1=M . From all such possible variants as a final result the program should choose the one with the minimum function value of total seats remoteness from the center. Say, — the row and the seat numbers of the most "central" seat. Then the function value of seats remoteness from the hall center is . If the amount of minimum function values is more than one, the program should choose the one that is closer to the screen (i.e. the row number xx is lower). If the variants are still multiple, it should choose the one with the minimum yly_{l} . If you did not get yet, your task is to simulate the work of this program.

输入格式

The first line contains two integers NN and KK ( 1<=N<=1000,1<=K<=991<=N<=1000,1<=K<=99 ) — the amount of requests and the hall size respectively. The second line contains NN space-separated integers MiM_{i} from the range [1,K][1,K] — requests to the program.

输出格式

Output NN lines. In the ii -th line output «-1» (without quotes), if it is impossible to find MiM_{i} successive seats in one row, otherwise output three numbers x,yl,yrx,y_{l},y_{r} . Separate the numbers with a space.

输入输出样例

  • 输入#1

    2 1
    1 1
    

    输出#1

    1 1 1
    -1
    
  • 输入#2

    4 3
    1 2 3 1
    

    输出#2

    2 2 2
    1 1 2
    3 1 3
    2 1 1
    
首页