简单题。

#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. spring mvc 解决 Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 异常

    org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro ...

  2. [实用技巧] Mac下面如何通过终端快速打开当前文件夹

    Mac mac里面其实很简单,直接输入 open .,注意是open + 英文句点. Windows windows里面是start .,注意是start  + 英文句点.

  3. JSP 错误处理方法

    web.xml中配置error-page标签 1.WEB工程中打开 web.xml 文件

  4. IOS代码收集

    http://mobile.51cto.com/hot-410417.htm 退回输入键盘: - (BOOL) textFieldShouldReturn:(id)textField{ [textFi ...

  5. php bz2扩展安装

    php bz2扩展安装 2017年09月22日 14:14:36 Cookie_1030 阅读数:1781   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...

  6. flask_SQLAlchemy 中常用的过滤和执行器

    常用的SQLAlchemy查询过滤器 过滤器 说明 filter() 把过滤器添加到原查询上,返回一个新查询 filter_by() 把等值过滤器添加到原查询上,返回一个新查询 limit 使用指定的 ...

  7. oracle的系统表

    -- DBA/ALL/USER/V_$/GV_$/SESSION/INDEX开头的绝大部分都是视图-- DBA_TABLES意为DBA拥有的或可以访问的所有的关系表.-- ALL_TABLES意为某一 ...

  8. MPP(大规模并行处理)简介

    1. 什么是MPP? MPP (Massively Parallel Processing),即大规模并行处理,在数据库非共享集群中,每个节点都有独立的磁盘存储系统和内存系统,业务数据根据数据库模型和 ...

  9. New Arrival MB SD Connect Compact 5 (MB SD C4) Star Diagnosis

    MB SD Connect Compact 5 has same function as SD C4 but with new design, support both cars and trucks ...

  10. 教你学会Linux/Unix下的vi文本编辑器

    vi编辑器是Unix/Linux系统管理员必须学会使用的编辑器.看了不少关于vi的资料,终于得到这个总结. 首先,记住vi编辑器的两个模式:1.命令模式 2.编辑模式. 在一个UNIX/Linux的s ...