Tuesday , December 6 2016
Home / C / Find the elements which created the smallest partial sum modulo P that is at least K

Find the elements which created the smallest partial sum modulo P that is at least K

In this problem, you will be given such a sequence and two integers P and K. Your task is to find the elements which created the smallest partial sum modulo P that is at least K.
 
For example, consider the following sequence of integers:
12     13     15     11     16     26     11
Here N = 7. Suppose K = 0 the answer is 0 since 12 + 13 + 15 + 11 = 5 and 68 mod 17 is 0.
You may assume 1 ≤ N ≤ 100000.Input
The first line of the input contains the number of test cases, T.
Each test case begins with a line containing three integers, NK and P. This is followed by the values of a1,a2, …, aN, one per line. 

Output
Output one line per test case, containing the elements which created the smallest partial sum modulo P that is at least K, as described above.

Example
Input:
1
7 2 17
12
13
15
11
16
26
11
 
Output:
11 16 26
 

solution in c

Also See:   c program for Best fit memory segment

Check Also

Hide Mouse Pointer C Program

How to Hide a Mouse Pointer Program in C : This program will show and hide ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.