DCP-92: Divided by Whom ? Back to All Problems

Medium Math > Basic Math


You are given an array of N elements, you need to make some pairs using all the elements of the array where each pair’s sum is divisible by a value K. Print the pairs in lexicographically smallest one first. Lets say you have two pair (x1, y1) and (x2, y2) , (x1, y1) will come before (x2, y2) if x1 < x2 or ( x1==x2 && y1 <= y2 ) And for each pair (x, y), x = min(x, y) and y = max(x, y) For example you have an array like this: [ 9, 1, 18, 2] and given value K = 10 You should print 1 9 2 18 Input: ------ Input starts with an integer T (≤ 3), denoting the number of test cases. The next line contains two integers N (1 ≤ N ≤ 10<sup>5</sup>), K (1 ≤ K ≤ 10<sup>9</sup>). The next line contains N space separated integers forming the array. There integers range in [0, 10<sup>9</sup>]. Output: ------- For each case, print the case number first. If it is possible to make some pairs using all the elements of the array where each pair’s sum is divisible by a value K then print all the pairs from the next line lexicographic-ally sorted way otherwise print "Not Possible" without quote. See the output section for better understanding Sample Input ------------ 1 4 10 9 1 18 2 Sample Output ------------- Case 1: 1 9 2 18


Problem Setter:

Ahmad Faiyaz

Please login to submit solution to this problem.

Problem Limits

Language Time Limit (seconds)
C 3.00
C++ 3.00
C++14 3.00
C# 6.00
Go 6.00
Java 6.00
JavaScript 6.00
Objective-C 6.00
Perl 6.00
PHP 6.00
Python 6.00
Python3 6.00
Ruby 6.00
VB.Net 6.00

Problem Stats

48/237

Solve/Submission

Ranking

# User Language Timing
01 feodorv C 0.08s
02 Robbinb1993 Cpp14 0.39s
03 moshiur_cse15 Cpp14 0.62s
04 Morass Cpp14 0.69s
05 Optimus_primeV2 Cpp14 0.83s
06 froghramar Cpp14 0.91s
07 daihan_mbstu Cpp14 0.92s
08 tariqiitju Cpp14 0.97s
09 saiful130104 Cpp14 1.05s
10 SKL12 Cpp14 1.07s
11 AlaminJust Cpp14 1.10s
12 Pure_Protea Cpp14 1.13s
13 Rakib05 Cpp 1.16s
14 RandyWaterhouse Cpp 1.17s
15 smriad Cpp14 1.19s
16 abdulmukit Cpp 1.19s
17 haasib Cpp14 1.20s
18 prantacse14 Cpp14 1.24s
19 sadia2427 Cpp14 1.26s
20 seyedssz Cpp14 1.33s
21 rayhan50001 Cpp14 1.42s
22 ahqmrf Cpp14 1.55s
23 rdas6313 Cpp14 2.03s
Feedback

Your feedback is our precious!



Or call +88 02 9853138 for support