Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b20b5ec

Browse files
jim and orders
1 parent 810fb62 commit b20b5ec

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

‎jim-and-the-orders.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
5+
process.stdin.resume();
6+
process.stdin.setEncoding('utf-8');
7+
8+
let inputString = '';
9+
let currentLine = 0;
10+
11+
process.stdin.on('data', inputStdin => {
12+
inputString += inputStdin;
13+
});
14+
15+
process.stdin.on('end', _ => {
16+
inputString = inputString.replace(/\s*$/, '')
17+
.split('\n')
18+
.map(str => str.replace(/\s*$/, ''));
19+
20+
main();
21+
});
22+
23+
function readLine() {
24+
return inputString[currentLine++];
25+
}
26+
27+
// Complete the jimOrders function below.
28+
function jimOrders(orders) {
29+
for (let i = 0; i < orders.length; i++) {
30+
orders[i][3] = i+1;
31+
orders[i][2] = orders[i][0] + orders[i][1];
32+
}
33+
orders.sort((x,y)=>x[2]-y[2]);
34+
return orders.map((order)=>order[3]);
35+
}
36+
37+
function main() {
38+
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
39+
40+
const n = parseInt(readLine(), 10);
41+
42+
let orders = Array(n);
43+
44+
for (let i = 0; i < n; i++) {
45+
orders[i] = readLine().split(' ').map(ordersTemp => parseInt(ordersTemp, 10));
46+
}
47+
48+
let result = jimOrders(orders);
49+
50+
ws.write(result.join(" ") + "\n");
51+
52+
ws.end();
53+
}

‎mark-and-toys.js‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
5+
process.stdin.resume();
6+
process.stdin.setEncoding('utf-8');
7+
8+
let inputString = '';
9+
let currentLine = 0;
10+
11+
process.stdin.on('data', inputStdin => {
12+
inputString += inputStdin;
13+
});
14+
15+
process.stdin.on('end', _ => {
16+
inputString = inputString.replace(/\s*$/, '')
17+
.split('\n')
18+
.map(str => str.replace(/\s*$/, ''));
19+
20+
main();
21+
});
22+
23+
function readLine() {
24+
return inputString[currentLine++];
25+
}
26+
27+
// Complete the maximumToys function below.
28+
function maximumToys(prices, k) {
29+
prices = prices.sort((x,y)=>x-y);
30+
for(let i=0;i<prices.length;i++){
31+
k = k - prices[i];
32+
if(k<0) return i;
33+
}
34+
}
35+
36+
function main() {
37+
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
38+
39+
const nk = readLine().split(' ');
40+
41+
const n = parseInt(nk[0], 10);
42+
43+
const k = parseInt(nk[1], 10);
44+
45+
const prices = readLine().split(' ').map(pricesTemp => parseInt(pricesTemp, 10));
46+
47+
let result = maximumToys(prices, k);
48+
49+
ws.write(result + "\n");
50+
51+
ws.end();
52+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /