CF15D.Map

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There is an area map that is a rectangular matrix n×mn×m , each cell of the matrix contains the average height of a corresponding area part. Peter works for a company that has to build several cities within this area, each of the cities will occupy a rectangle a×ba×b cells on the map. To start construction works in a particular place Peter needs to remove excess ground from the construction site where a new city will be built. To do so he chooses a cell of the minimum height within this site, and removes excess ground from other cells of the site down to this minimum level. Let's consider that to lower the ground level from h2h_{2} to h1h_{1} ( h1<=h2h_{1}<=h_{2} ) they need to remove h2h1h_{2}-h_{1} ground units.

Let's call a site's position optimal, if the amount of the ground removed from this site is minimal compared to other possible positions. Peter constructs cities according to the following algorithm: from all the optimum site's positions he chooses the uppermost one. If this position is not unique, he chooses the leftmost one. Then he builds a city on this site. Peter repeats this process untill he can build at least one more city. For sure, he cannot carry out construction works on the occupied cells. Would you, please, help Peter place cities according to the algorithm?

输入格式

The first line contains four space-separated integers: map sizes nn , mm and city sizes aa , bb ( 1<=a<=n<=10001<=a<=n<=1000 , 1<=b<=m<=10001<=b<=m<=1000 ). Then there follow nn lines, each contains mm non-negative space-separated numbers, describing the height matrix. Each number doesn't exceed 10910^{9} .

输出格式

In the first line output kk — the amount of constructed cities. In each of the following kk lines output 3 space-separated numbers — the row number and the column number of the upper-left corner of a subsequent construction site, and the amount of the ground to remove from it. Output the sites in the order of their building up.

输入输出样例

  • 输入#1

    2 2 1 2
    1 2
    3 5
    

    输出#1

    2
    1 1 1
    2 1 2
    
  • 输入#2

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

    输出#2

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