CF10B.Cinema Cashier

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. 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 M people, who come to watch a movie, want necessarily to occupy M successive seats in one row. Let's formulate the algorithm, according to which the program chooses seats and sells tickets. As the request for M seats comes, the program should determine the row number x and the segment [y__l, y__r] of the seats numbers in this row, where y__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 x is lower). If the variants are still multiple, it should choose the one with the minimum y__l. If you did not get yet, your task is to simulate the work of this program.

伯兰的所有电影院影厅均为 KK 行 ×\times KK 列的矩形,其中 KK 为奇数。行号与座位号均从 11 编号至 KK。出于安全原因,前往售票处购票的观众不得自行选择座位。过去由售票员人工选座,而如今该任务由一个专用的座位分配程序负责。研究发现,伯兰绝大多数居民去电影院是为了观看电影,因此他们希望尽可能坐得靠近影厅中心。此外,一个由 MM 人组成的观影团体,必须占据同一行中连续的 MM 个座位。

下面给出该程序在接到 MM 个座位请求时所采用的选座与售票算法:
程序需确定行号 xx,以及该行中座位编号区间 [yl, yr][y_l,\,y_r],满足 yr−yl+1=My_r - y_l + 1 = M。在所有满足条件的可行方案中,程序应选择使“所有被选座位到影厅中心的总距离”函数值最小的那个方案。设 为影厅最“中心”座位的行号与列号,则座位 (i,j)(i,j) 到影厅中心的距离函数值为:
。

若存在多个方案具有相同的最小距离函数值,则程序应从中选择更靠近银幕(即行号 xx 更小)的方案;若仍存在多个方案,则选择其中 yly_l 最小者。

若你尚未完全理解,请注意:你的任务就是模拟该程序的工作过程。

输入格式

The first line contains two integers N and K (1 ≤ N ≤ 1000, 1 ≤ K ≤ 99) — the amount of requests and the hall size respectively. The second line contains N space-separated integers M__i from the range [1, K] — requests to the program.

第一行包含两个整数 NN 和 KK(1 ≤ N ≤ 10001 \leq N \leq 1000,1 ≤ K ≤ 991 \leq K \leq 99)—— 分别表示请求的数量和大厅的容量。
第二行包含 NN 个空格分隔的整数 MiM_i,每个 MiM_i 均在区间 [1, K][1, K] 内—— 表示对程序的请求。

输出格式

Output N lines. In the i-th line output «-1» (without quotes), if it is impossible to find M__i successive seats in one row, otherwise output three numbers x, y__l, y__r. Separate the numbers with a space.

输出 N 行。在第 i 行中,若无法在某一行中找到 M__i 个连续的空座位,则输出 «-1»(不带引号);否则输出三个数 x, y__l, y__r。各数之间用空格分隔。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页