There is a problem with TwoSum. Big data failed in the test.

topic description

this is the title on hackerrank
https://www.hackerrank.com/ch.

my code failed the test in the following data.
https://hr-testcases-us-east-.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

    "use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});

process.stdin.on("end", function() {
    inputString = inputString.replace(/\s*$/, "")
        .split("\n")
        .map(str => str.replace(/\s*$/, ""));

    main();
});

function readLine() {
    return inputString[currentLinePP];
}
function whatFlavors(cost, money) {
    const cpyarr = cost.slice(0);
    cost.sort((a,b)=>{
        return b-a;
    });    
   const start = findStartPoint(cost, money, 0); 
    // console.log(start);
   for(let i=start;i<cost.length;iPP){
       if(cost[i]<money){
          let remain = money -  cost[i];
           let remainIndex = cost.indexOf(remain,i+1);
           if(remainIndex!=-1){

                let first = cpyarr.indexOf(cost[i]);
                let last = cpyarr.indexOf(cost[remainIndex]);
                if(last === first){
                  last = cpyarr.indexOf(cost[remainIndex],first)+2;
                  firstPP;
                }else{
                  lastPP;
                  firstPP;
                };
                let temp =0;
                if(first>=last){
                  temp = first;
                  first = last;
                  last = temp;
                };
               return `${first} ${last}`
           }
       };
   }
   return `-1 -1`;
}

function findStartPoint(arr, money,startpoint){
    let newarr = arr.slice(0);
    let middle = Math.floor(newarr.length/2);
     if(newarr[middle]>money){
        return findStartPoint(newarr.splice(middle),money,middle);
     }else if(newarr[middle] === money){
          return middle;
     }else{
          return startpoint;
     }  
}

function main() {
    const t = parseInt(readLine(), 10);

    for (let tItr = 0; tItr < t; tItrPP) {
        const money = parseInt(readLine(), 10);

        const n = parseInt(readLine(), 10);

        const cost = readLine().split(" ").map(costTemp => parseInt(costTemp, 10));

        const result = whatFlavors(cost, money);
        console.log(result);
    }
}

what result do you expect? What is the error message actually seen?

Mar.26,2021
Menu