Submission #6134799


Source Code Expand

Copy
"use strict";

const main = arg => {
  arg = arg.trim().split("\n");
  const N = parseInt(arg[0].split(" ")[0]);
  const x = parseInt(arg[0].split(" ")[1]);
  a = new Array(N);
  tmp = arg[1].split(" ");
  let sum =0;
  for(i=0;i<N;i++){
	  a[i]=parseInt(tmp[i]);
	sum+=a[i];
  }
  let num=x;
  a.sort(function(a,b){return a-b});
  
  let ans = 0;
  
  for(i=0;i<N;i++){
	  if(x>=a[i]){
		ans++;
		x-=a[i];
	  }else{
		  break;
	  }
  }
  
  if(num>sum){
	  ans=N-1;
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Submission Info

Submission Time
Task A - Candy Distribution Again
User oimo23
Language JavaScript (node.js v5.12)
Score 0
Code Size 582 Byte
Status

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0 / 200 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt
0_01.txt
0_02.txt
0_03.txt
1_00.txt
1_01.txt
1_02.txt
1_03.txt
1_04.txt
1_05.txt
1_06.txt
1_07.txt