Submission #6134815


Source Code Expand

Copy
"use strict";

const main = arg => {
  arg = arg.trim().split("\n");
  const N = parseInt(arg[0].split(" ")[0]);
  let x = parseInt(arg[0].split(" ")[1]);
  let a = new Array(N);
  let tmp = arg[1].split(" ");
  let sum =0;
  for(let 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(let 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 200
Code Size 596 Byte
Status
Exec Time 53 ms
Memory 7500 KB

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 200 / 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 52 ms 7372 KB
0_01.txt 53 ms 7372 KB
0_02.txt 53 ms 7372 KB
0_03.txt 53 ms 7372 KB
1_00.txt 53 ms 7372 KB
1_01.txt 53 ms 7500 KB
1_02.txt 53 ms 7500 KB
1_03.txt 53 ms 7500 KB
1_04.txt 53 ms 7500 KB
1_05.txt 53 ms 7500 KB
1_06.txt 53 ms 7500 KB
1_07.txt 53 ms 7500 KB