Programming Puzzle - N Teams K Wins each
Style

You are lacking consistency in the spacing in assignments.

Organisation

It might be worth extracting the algorithm in a function. It makes code easier to read and to test.

&lt;?php
function guessChronology($n, $k)
{
    if ($n * $k &gt; ($n * ($n - 1)) / 2) {
        return "-1\n";
    }
    $output = $n*$k."\n";
    $winMap = array();
    for ($i = 1; $i &lt;= $n; $i++) {
        $winMap[$i] = 0;
    }
    for ($i = 1; $i &lt;= $n; $i++) {
        for ($j = $i + 1; $j &lt;= $n; $j++) {
            if ($winMap[$i] &lt; $k) {
                $output .= "$i $j\n";
                $winMap[$i] += 1;
            } else if ($winMap[$j] &lt; $k) {
                $winMap[$j] += 1;
                $output .=  "$j $i\n";
            }
        }
    }
    return $output;
}

$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum = explode(" ",trim($n));
$n = $dum[0];
$k = $dum[1];
echo guessChronology($n, $k);
?&gt;


Re-using functions

You can use array_fill to write $winMap = array_fill(1, $n, 0);