简单题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
using namespace std; const int maxn=+;
int n,m;
long long a[maxn];
long long b[maxn]; bool cmp(const long long &a,const long long &b)
{
return a>b;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
scanf("%d",&m);
for(int i=;i<=m;i++) scanf("%lld",&b[i]);
sort(a+,a++n);
sort(b+,b++m);
long long ans=;
for(int i=;i<=min(m,n);i++)
{
if(a[i]>=) break;
if(b[i]>=) break;
ans=ans+a[i]*b[i];
}
sort(a+,a++n,cmp);
sort(b+,b++m,cmp); for(int i=;i<=min(m,n);i++)
{
if(a[i]<=) break;
if(b[i]<=) break;
ans=ans+a[i]*b[i];
}
printf("%lld\n",ans);
return ;
}

PAT (Advanced Level) 1037. Magic Coupon (25)的更多相关文章

  1. PTA(Advanced Level)1037.Magic Coupon

    The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...

  2. 【PAT甲级】1037 Magic Coupon (25 分)

    题意: 输入一个正整数N(<=1e5),接下来输入N个整数.再输入一个正整数M(<=1e5),接下来输入M个整数.每次可以从两组数中各取一个,求最大的两个数的乘积的和. AAAAAccep ...

  3. PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)

    1037 Magic Coupon (25 分)   The magic shop in Mars is offering some magic coupons. Each coupon has an ...

  4. PAT Advanced 1037 Magic Coupon (25) [贪⼼算法]

    题目 The magic shop in Mars is ofering some magic coupons. Each coupon has an integer N printed on it, ...

  5. PAT甲题题解-1037. Magic Coupon (25)-贪心,水

    题目说了那么多,就是给你两个序列,分别选取元素进行一对一相乘,求得到的最大乘积. 将两个序列的正和负数分开,排个序,然后分别将正1和正2前面的相乘,负1和负2前面的相乘,累加和即可. #include ...

  6. 1037 Magic Coupon (25分)

    The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...

  7. 1037. Magic Coupon (25)

    #include<iostream> #include<vector> #include<stdio.h> #include<algorithm> us ...

  8. PAT (Advanced Level) 1114. Family Property (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  9. PAT (Advanced Level) 1109. Group Photo (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

随机推荐

  1. Java长存!12个Java长久占居主要地位的原因

    Java长存!12个Java长久占居主要地位的原因 我们很容易就会遗忘那些曾经在猿群中大热而又被各种新技术掩盖直至堙灭的技术的价值.就拿COBOL这个老猿们当年所用的神器来说,就跟条死鱼一样被现代猿基 ...

  2. 在SAP UI中使用纯JavaScript显示产品主数据的3D模型视图

    在Jerry写这篇文章时,通过Google才知道,SAP其实是有自己的3D模型视图显示解决方案的. 故事要从Right Hemisphere说起,这是一家专业的企业级2D/3D模型浏览及转换的软件供应 ...

  3. SQLite – 删除表

    SQLite -删除表 SQLite DROP TABLE语句用于删除一个表定义和所有相关的数据,索引.触发器.约束和规范许可表. 你使用这个命令时必须小心,因为一旦一个表被删除然后表中所有可用的信息 ...

  4. SQLite -插入查询

     SQLite -插入查询 SQLite插入语句是用来添加新行数据到数据库中的一个表. 语法: 有两种基本的插入语句的语法如下: INSERT INTO TABLE_NAME (column1, co ...

  5. 如何开发 Laravel 扩展包并发布到 Composer

    如何开发 Laravel 扩展包并发布到 Composer  发布于 2019-01-22 cxp1539  1074 Vie   开发扩展包 我们来做一个根据第一个字符或者汉字生成头像的larave ...

  6. env - 在重建的环境中运行程序

    SYNOPSIS(总览) env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...] DESCRIPTION(描述) 设置环境中的每个NAME为VAL ...

  7. 暑假集训 || 树DP

    树上DP通常用到dfs https://www.cnblogs.com/mhpp/p/6628548.html POJ 2342 相邻两点不能同时被选 经典题 f[0][u]表示不选u的情况数,此时v ...

  8. qcloudsms_py

    qcloudsms_py from qcloudsms_py import SmsVoicePromptSender from qcloudsms_py.httpclient import HTTPE ...

  9. WebDriverException: Message: unknown error: Chrome failed to start: crashed

    the last answer WebDriverException: Message: unknown error: Chrome failed to start: crashed

  10. springboot @test 使用

    @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) public class Springtest { ...