-
Notifications
You must be signed in to change notification settings - Fork 0
/
two-arrays.php
50 lines (35 loc) · 1.01 KB
/
two-arrays.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
* Complete the 'twoArrays' function below.
*
* The function is expected to return a STRING.
* The function accepts following parameters:
* 1. INTEGER k
* 2. INTEGER_ARRAY A
* 3. INTEGER_ARRAY B
*/
function twoArrays($k, $A, $B)
{
sort($A);
rsort($B);
for ($x = 0, $l = count($A); $x < $l; $x++) {
if ($A[$x] + $B[$x] < $k) {
return 'NO';
}
}
return 'YES';
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$q = intval(trim(fgets(STDIN)));
for ($q_itr = 0; $q_itr < $q; $q_itr++) {
$first_multiple_input = explode(' ', rtrim(fgets(STDIN)));
$n = intval($first_multiple_input[0]);
$k = intval($first_multiple_input[1]);
$A_temp = rtrim(fgets(STDIN));
$A = array_map('intval', preg_split('/ /', $A_temp, -1, PREG_SPLIT_NO_EMPTY));
$B_temp = rtrim(fgets(STDIN));
$B = array_map('intval', preg_split('/ /', $B_temp, -1, PREG_SPLIT_NO_EMPTY));
$result = twoArrays($k, $A, $B);
fwrite($fptr, $result . "\n");
}
fclose($fptr);