+ 1

Help me Debug!!!

You are given an array of integers a1,a2,…,an of length n and an integer k . Two players are playing a game. The first player chooses an index i . Then the second player chooses a different index j . The first player wins if |ai−aj| is not divisible by k . Otherwise, the second player wins. We play as the first player. Determine whether it is possible to win, and if so, which index i should be chosen. The absolute value of a number x is denoted by |x| and is equal to x if x≥0, and −x otherwise. Input Each test contains multiple test cases. The first line of input contains a single integer t The first line of each test case contains two integers n and k The second line of each test case contains n integers a1,a2,…,an Output For each test case, if it is impossible for the first player to win, print "NO" (without quotes). Otherwise, print "YES" (without quotes) and on the next line the appropriate index 1≤i≤n . If there are multiple solutions, print any of them. You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer. Example Input 7 3 2 1 2 3 4 2 1 2 4 5 5 3 10 7 3 4 5 5 3 1 31 15 55 36 2 1 17 17 2 2 17 18 1 3 6 Output YES 2 NO YES 3 NO NO YES 2 YES 1 My code - https://www.sololearn.com/en/compiler-playground/cBpV5ggb6wFd why doesnt my code satisfy all the test cases however it satisifies all the cases in given above example ,,, help me debug!!!!

14th Dec 2024, 11:36 AM
Imrtl
Imrtl - avatar
3 Réponses
+ 1
For app users the link is https://sololearn.com/compiler-playground/cBpV5ggb6wFd/?ref=app Imrtl when I tested the code the next-to-last test case had different output. (It printed YES 1 instead of the expected YES 2). It is hard to tell whether the code logic models the task description. Are you certain that it is correctly testing abs(a[i] - a[j])%k?
14th Dec 2024, 3:45 PM
Brian
Brian - avatar
0
Brian nah bro that doesn't matter because in the question they said that print the index of any so 1 or 2 doesn't matter as both are right ,, this code actually passed the test cases mentioned above it failed in some other test cases which I don't know(it's runned in codeforces)
14th Dec 2024, 5:01 PM
Imrtl
Imrtl - avatar
0
Brian and about that absolute ai-aj % k part yes it does, as remained doesn't affect for opposite signs of dividend
14th Dec 2024, 5:04 PM
Imrtl
Imrtl - avatar