๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.61K photos
3 videos
95 files
10.6K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
#include<stdio.h>
#include<stdlib.h>
long long arr[100005];
int cmpfunc (const void * a, const void * b)
{
   return ( *(int *)a - *(int *)b );
}
int main()
{
long long n,c,i,j,ans=0,a,sum=0;
scanf("%lld %lld",&n,&c);
for(i=0;i<n;i++)
{scanf("%lld",arr+i);sum+=arr[i];}
qsort(arr,n,sizeof(long long),cmpfunc);

for(i=0;i<n-1;i++)
{
sum-=arr[i];
ans+=sum-(arr[i]*(n-1-i));
}
if(n>1){
a=n/2;
ans+=a*(a+1)*c;
a=(n-1)/2;
ans+=a*(a+1)*c;
}
printf("%lld",ans);
return 0;
}

The Strange Array โœ…
(C++)