problem statement is here
#include<stdio.h>
int main(){
long long int a,b,ar[100000],i,j,u,p,t,sum;
scanf("%lld",&t);
while(t--){
sum=0;
scanf("%lld",&a);
scanf("%lld",&ar[0]);
u=0;
for(i=1;i<a;i++){
scanf("%lld",&ar[i]);
p=ar[i]-ar[i-1];
u+=(i*p);
sum+=u;
}
printf("%lld\n",sum);
}
return 0;
}
plz explain answer
ReplyDelete