Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Andrew and the Meatballs

$
0
0

below is code in php. its showing wrong answer please help

#!C:\wamp\bin\php\php5.3.13\php.exe -q
<?php
    fscanf(STDIN,"%d",$tt);
    $res[]='';
    for($i=0;$i<$tt;$i++){
        fscanf(STDIN,"%d %d",$n,$k);
        $t=explode(' ',trim(fgets(STDIN)));
        rsort($t);
        $sum=0;
        $c=0;
        $f=0;
        foreach($t as $a){
            $sum+=$a;
            $c++;
            if($sum>=$k){
                $f=1;
                break;
            }
        }
        if($f==1)
            $res[$i]=$c;
        else
            $res[$i]=-1;
    }
    foreach($res as $re)
        printf("%d\n",$re);
    exit(0); 
?>

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>