Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const N = parseInt(readline());
- var inputs = readline().split(' ');
- let supZero = 0;
- let arrayTemp = [];
- let search = true;
- while ( search ){
- inputs = down(inputs);
- for (let index = 0; index < arrayTemp.length; index++) {
- if ( inputs.filter(x => x !=0).sort().join('') === arrayTemp[index].filter(x => x != 0 ).sort().join('')){
- search = false;
- console.log(arrayTemp.length - index);
- break;
- }
- }
- arrayTemp.push(inputs.filter(x => x !=0));
- if ( arrayTemp.length > 100){
- arrayTemp = [];
- }
- }
- function down(arr){
- arr.map(function(value,i){
- if ( value != 0 ){
- arr[i] = value - 1 ;
- supZero++;
- }
- })
- arr.push(supZero);
- supZero = 0;
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement