-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_chef_query.c
46 lines (46 loc) · 979 Bytes
/
code_chef_query.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
int main(void) {
int test,index=0,size,key,carry=0,days=0;
scanf("%d",&test);
while(test>0)
{
scanf("%d %d",&size,&key);
int array[size];
for(index=0;index<size;index++)
scanf("%d",&array[index]);
index=0;
carry=0;
days=0;
while(index<size)
{
if(array[index]+carry<key)
{
days=index+1;
}
else if(index==size-1 && array[index]+carry-key<key)
{
carry=0;
days++;
}
else if(array[index]+carry>=key)
{
array[index]+=carry;
carry=array[index]-key;
days=index+1;
}
index++;
}
if(carry>0)
{
carry=array[size-1];
while(carry>0)
{
carry-=key;
days++;
}
}
printf("%d\n",days);
test--;
}
return 0;
}