## 12028 - A Gift from the Setter

Moderator: Board moderators

unaisah
New poster
Posts: 1
Joined: Tue Jul 26, 2011 12:29 am

### 12028 - A Gift from the Setter

why WA ? i think my algorithm is not working properly.Any hints ??

Code: Select all

``````#include<iostream>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
using namespace std;

long long  n,k,c,t;
long long  y=0,xx,temp;
long long  sum (long long  aa[],long long  nn)
{
long long  sum=0,sum2=0;
int i;
long count=1;
for(i=1;i<nn;i++)
{
sum2+=aa[i];
temp=y-sum2;
temp=abs(temp-(aa[i]*(nn-count)));
sum+=temp;
count++;
}

return sum;
}

int main()
{

int li,test,j;
scanf("%d",&test);
for(j=1;j<=test;j++)
{
long long a[100099];
y=0;
scanf("%lld%lld%lld%lld",&k,&c,&n,&t);
y=t;
a[1]=t;
for(li=2;li<=n;li++)
{
a[li]=(k*a[li-1]+c)%1000007;

y+=a[li];
}
xx=sum(a,n);
if(j<test)
printf("Case %d: %lld\n",j,xx);
else
printf("Case %d: %lld",j,xx);

}

return 0;
}
``````

amin__
New poster
Posts: 10
Joined: Thu Jul 01, 2010 10:44 am

### Re: 12028

I did not understand your code completely..but I think there is a problem in the for loop in sum routine..

I randomly choose two input and they fail in your solution...inputs are:
2
10 10 10 12
10 10 10 100

output should be
Case 1: 4639073
Case 2: 5240402

hope these will help

robot
New poster
Posts: 29
Joined: Sun May 24, 2009 8:39 pm

### Re: 12028

Hi unaisah ..
you have a simple mistake...
A sort function require....According ur code.....
a[0]=t;
for(li=1;li<n;li++)
{
a[li]=(k*a[li-1]+c)%1000007;
y+=a[li];
}
sort(&a[0],&a[n]);
xx=sum(a,n);
printf("Case %d: %lld\n",j,xx);

In Sum funtion:
for(i=0;i<nn;i++)
{

}
return sum

I hope u will get Accepted.........
ASU(SUST)