結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2020-04-26 16:29:32 |
| 言語 | JavaScript (node v23.5.0) |
| 結果 |
AC
|
| 実行時間 | 66 ms / 2,000 ms |
| コード長 | 1,251 bytes |
| コンパイル時間 | 67 ms |
| コンパイル使用メモリ | 6,944 KB |
| 実行使用メモリ | 41,204 KB |
| 最終ジャッジ日時 | 2024-10-13 01:45:02 |
| 合計ジャッジ時間 | 3,067 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
function main(input) {
let [n, m] = getIntegers(input);
let c = getIntegers(input);
let ans = 0;
c.sortByIntegers();
for(let i=0; i<n; i++) {
m -= c[i];
if(m < 0) break;
ans++;
}
console.log(ans);
}
//-- functions ------------------------------------
function getIntegers(lines) {
return lines.shift().split(" ").map(function(e) {
return Number(e);
});
}
function getStrings(lines) {
return lines.shift().split(" ");
}
function twoDimensionalArray(h, w, value) {
const list = new Array(h);
for(let i=0; i<h; i++) {
list[i] = new Array(w).fill().map(function(e) {
return value.constructor == Array ? Array.from(value) : value;
});
}
return list;
}
//-- Array -------------------------------------------
Array.prototype.pushNoSameValue = function(...values) {
values.forEach(function(e) {
if(!this.includes(e)) {
this.push(e);
}
}, this);
};
Array.prototype.sortByIntegers = function() {
this.sort(function(a, b) {
return a - b;
});
};
Array.prototype.oneLineString = function() {
let str = "";
this.forEach(function(e, i) {
if(i > 0) str += " ";
str += e;
});
return str;
};
main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));
jp_ste