On Sunday, 27 July 2008 09:57:16 UTC+5:30, Huabin  wrote:
> yes, it's such a simple problem.
> my c++ code looks like this:
> 
> sort(v1.begin(), v1.end());
> sort(v2.begin(), v2.end());
> return inner_product(v1.begin(), v1.end(), v2.rbegin(), 0);
> 
> I submitted my result for the small data set and was notified correct.
> 
> 
> however, my result for the large data set is wrong, why?
> 
> 
> 2008/7/26 Karol <[email protected]>
> 
> 
> 
> Hello everyone,
> 
> I've just waked up. Just tell me - has anyone used the simplest
> 
> solution for the Minimum Scalar Product that is:
> 
> 1) sort vector1
> 
> 2) sort vector2
> 
> 3) multiply v1[i] * v2[-i] and sum the results
> 
> where [-i] means i from the end of vector.
> 
> 4) return the sum
> 
> 
> 
> Regards,
> 
> Karol
> 
> 
> 
> 
> 
> 
> -- 
> Huabin Zheng
> Sensor Networks and Application Research Center, GUCAS

Hi Huabin,
this is because of overflow happening inside inner_product. declare v1 and v2 
as vector<long long> to avoid this. hope the return type of your function too 
is long long. this should correct your problem.

regards,
Sreejith

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/38d92203-c6e9-47d8-917c-0aad86ede102%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to