Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const binarySearch = function (start, finish, value)
- {
- let guess;
- let min = start;
- let max = finish;
- while (min <= max)
- {
- guess = Math.floor((min + max) / 2);
- if (guess === value)
- return guess;
- else if (guess < value)
- min = guess + 1;
- else
- max = guess - 1;
- }
- return -1;
- };
- let lineReader = require('readline').createInterface({
- input: require('fs').createReadStream('input.txt')
- });
- lineReader.on('line', function (line)
- {
- if (line !== '')
- {
- let haveAns = false;
- let row_input = line.split(' ');
- const s = parseInt(row_input[0]);
- const l1 = parseInt(row_input[1]);
- const r1 = parseInt(row_input[2]);
- const l2 = parseInt(row_input[3]);
- const r2 = parseInt(row_input[4]);
- for (let i = l1; i <= r1; i++)
- {
- let tmp = binarySearch(l2, r2, s - i);
- if (tmp !== -1)
- {
- console.log(i, tmp);
- haveAns = true;
- break;
- }
- }
- if (!haveAns)
- {
- console.log(-1);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement