Best Sums

All submissions for this problem are available.
Given a sequence of positive integers a_{1},
a_{2}, …, a_{N}, and 1 ≤
i ≤ j ≤ N, the partial sum from
i to j is a_{i} +
a_{i+1} + … + a_{j}.
In this problem, you will be given such a sequence and two
integers P and K. Your task is to find 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 = 2 and P = 17.
Then, the answer is 2 because 11+16+26 = 53 and 53 mod 17 is 2. On
the other hand, if K = 0 the answer is 0 since 15 + 11 + 16 +
26 = 68 and 68 mod 17 is 0.
Input format
The first line contains three integers N, K and
P. This is followed by N lines each containing a
single integer.
You may assume 1 ≤ N ≤ 100000.
Output format
A single integer indicating the minimum possible segment sum modulo
P that is at least K.
Example:
Sample Input
7 2 17 12 13 15 11 16 26 11
Sample Output
2
Author:  admin 
Tags  admin 
Date Added:  30072009 
Time Limit:  0.460123 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 