蓝桥杯-算法提高 最小乘积(提高型)

问题描述

给两组数,各n个。
请调整每组数的排列顺序,使得两组数据相同下标元素对应相乘,然后相加的和最小。要求程序输出这个最小值。
例如两组数分别为:1 3  -5和-2 4 1

那么对应乘积取和的最小值应为:
(-5) * 4 + 3 * (-2) + 1 * 1 = -25

输入格式

第一个行一个数T表示数据组数。后面每组数据,先读入一个n,接下来两行每行n个数,每个数的绝对值小于等于1000。
n<=1000,T<=10

输出格式

一个数表示答案。

样例输入

231 3 -5-2 4 151 2 3 4 51 0 1 0 1

样例输出

-256

参考代码

此处为隐藏的内容!
发表评论并刷新,才能查看
俊霖

发表评论

您必须

目前评论:6   其中:访客  6   博主  0


    Warning: A non-numeric value encountered in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/comment-template.php on line 20
  1. 雪露 5

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  2. 雪露 5

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  3. xiaweiyidengwo 4

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  4. ymx200181 5

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  5. Lions 3

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  6. 漫光 0

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566