HELPVOD: Need help

I am solving HELPVOD but my implementation seems to throw WA on codechef judge. Please help me in finding the error or the test cases it is failing. My implementation:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	    cin>>a[i];
    sort(a,a+n);
    int sum,ans;
    sum = ans = 0;
    for(int i=0;i<n-1;i++)
    {
        ans = a[i]*a[i+1];
        sum += ans;
        //<<sum<<" ";
    }
    cout<<sum<<endl;
	
	return 0;
}

yes bcoz ur using int for sum and in place of int u must use long long.here is my link https://www.codechef.com/viewsolution/17925615

1 Like

i have edited ur code and used long long and it has given write verdict.
pls do upvote

thank you…