Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Trimming Cables
- Young Seryozha is the junior IT at the trendiest coworking space (Campus V, V stands for Vladivostok) and he's been assigned with an extremely boring task. He has to trim all the cables hanging from the ceiling at the server room and he just can't find the inner strength to begin.
- So, to brighten up his day (and waste a little time), he decides to trim those cables by following specific rules: he identifies the shortest cable and then he trims all the cables exactly as much as the shortest's length. This process is repeated until all cables are leveled with the ceiling. Meanwhile, he counts the number of trims performed and at the end of the day, he will log this number into JIRA.
- ----- ----- ----- -----
- | | | | | |
- | | |
- |
- 3 trims 2 trims 1 trims 0 trims (total 6 trims performed)
- Input
- Exactly one line:
- the cables (numbers, separated by a space)
- Output
- Exactly one line:
- the number of of trims performed
- Constraints
- 0 < total cables < 2000
- 0 < cable length < 500
- Sample tests
- Input
- 3 1 2
- Output
- 6
- Input
- 2 6 2
- Output
- 4
- JavaScript
- let input = [
- '3 1 2'
- // '2 6 2'
- ]
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- let cables = gets().split(' ').map(Number);
- cables.sort(((a, b) => b - a));
- cables = [... new Set(cables)];
- let counter = 0;
- let sum = 0;
- cables.map(par => sum += par);
- print(cables, sum);
- for (let i = 0; i < cables.length; i++) {
- for (let j = 0; j < cables[i]; j++) {
- sum = sum - cables[cables.length - 1];
- if (sum < 0) {
- break;
- }
- counter++;
- }
- }
- print(counter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement