You are not logged in. Please login at www.codechef.com to post your questions!

×

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;
}

asked 21 Mar '18, 15:48

montycs's gravatar image

0★montycs
1057
accept rate: 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

link

answered 21 Mar '18, 16:19

gyanendra371's gravatar image

3★gyanendra371
2936
accept rate: 33%

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

(21 Mar '18, 16:20) gyanendra3713★

thank you..

(21 Mar '18, 17:32) montycs0★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,718
×832
×62

question asked: 21 Mar '18, 15:48

question was seen: 128 times

last updated: 21 Mar '18, 17:32