using
System;
using
System.Collections.Generic;
public
class
GFG {
public
static
int
accumulate(List<
int
> ll,
int
i,
int
j)
{
int
sum = 0;
while
(i < j) {
sum += ll[i];
i++;
}
return
sum;
}
public
static
List<
int
> makeDivisble(
int
[] arr,
int
n,
int
k)
{
List<
int
> b1 =
new
List<
int
>();
List<
int
> b2 =
new
List<
int
>();
int
c, suml, sumr, index, rem;
for
(
int
i = 0; i < n; i++)
b1.Add(arr[i] % k);
for
(
int
j = 0; j < n; j++)
if
((arr[j] % k) != 0)
b2.Add(k - (arr[j] % k));
else
b2.Add(0);
c = 0;
int
mini = Int32.MaxValue;
suml = 0;
sumr = 0;
index = -1;
for
(c = 0; c < n; c++) {
suml = accumulate(b1, 0, c + 1);
sumr = accumulate(b2, c + 1, b2.Count);
if
(suml >= sumr) {
rem = suml - sumr;
if
(rem < mini) {
mini = rem;
index = c;
}
}
}
List<
int
> ans =
new
List<
int
>();
ans.Add(index);
ans.Add(mini);
return
ans;
}
static
public
void
Main()
{
int
[] arr = { 1, 14, 4, 41, 1 };
int
k = 7;
int
n = arr.Length;
List<
int
> ans =
new
List<
int
>();
ans = makeDivisble(arr, n, k);
Console.WriteLine(ans[0] +
" "
+ ans[1]);
}
}