#!/usr/bin/perl

$DEBUG = 0;

sub comparer {
    if ($a == $b) {
        return( 0 );
    } elsif ($a > $b) {
        return( -1 );
    } else {
        return( 1 );
    }
}

chomp( $notesAConserver = <STDIN> );
chomp( $nombreDeNotes = <STDIN> );
chomp( $maxNote = <STDIN> );
$totalMax = $notesAConserver * $maxNote;

if ($DEBUG) {
    print "notesAConserver = $notesAConserver\n";
    print "nombreDeNotes = $nombreDeNotes\n";
    print "maxNote = $maxNote\n";
    print "totalMax = $totalMax\n";
}

$separateur = " ";

$grandTotal = 0;
while ($ligne = <STDIN>) {
    local(@lesNotes, @lesNotesOrd);
    $noteDefinie = 1;
    $ligne =~ s/[ ]+/ /g;
    @items = split(/$separateur/, $ligne);
    $codeP = $items[0];
    $totalNote = 0;
    $totalTravaux = 0;
    for ($i = 0; $i < $nombreDeNotes; $i++) {
	$j = $i+1;
	$note = $items[$j];
	push(@lesNotes, $note);
    }

    @lesNotes = sort comparer @lesNotes;
    $totalNote = 0;
    for( $i = 0; $i < $notesAConserver; $i++ ) {
	$totalNote += $lesNotes[$i];
    }
    $totalNote = $totalNote > $totalMax ? $totalMax : $totalNote;
    print sprintf "$codeP %4d", $totalNote;
    print "\n";
}

