简单题。

#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. sql语句分为三类(DML,DDL,DCL)-介绍

    本文知识来源自:<Oracle专家高级编程> 分享作者:Vashon 时间:20150415 DDL is Data Definition Language statements. Som ...

  2. es5/6数组遍历以及常用的一些方法

    数组的遍历方法 1...for(var i=0;i<arr.length;i++){ } ---------------------------------------------------- ...

  3. liunx+mysql数据库管理

    源码安装 查询是否安装:  rpm -aq |grep mysql 1.下载yum 源            wget 'https://dev.mysql.com/get/mysql57-commu ...

  4. Linux之用户权限管理

    chmod(更改目录或文件权限) 在linux中,文件的权限分为3中,拥有者,群组,其他人.而chmod则是对权限更改的命令. u 表示该文件的拥有者,g 表示与该文件的拥有者属于同一个组,o 表示其 ...

  5. python_对字符串操作.join() 效率 比 + 效率高

    将列表中的字符拼接成字符串时,有两种方式 方式1:使用join()方法,将列表转为字符串 方式2:使用+运算符,循环遍历 import time str1 = ['a','b','c','d','e' ...

  6. docker client和daemom

    client 模式 docker命令对应的源文件是docker/docker.go, docker [options] command [arg...] 其中options参数为flag,任何时候执行 ...

  7. 最短路 || POJ 1847 Tram

    POJ 1847 最短路 每个点都有初始指向,问从起点到终点最少要改变多少次点的指向 *初始指向的那条边长度为0,其他的长度为1,表示要改变一次指向,然后最短路 =========高亮!!!===== ...

  8. day13 函数模块之序列化 random 模块 os模块 sys模块 hashlib模块 collections模块

    json import json dic = {'k1':'v1','k2':'v2','k3':'v3'} str_dic = json.dumps(dic) #序列化:将一个字典转换成一个字符串 ...

  9. 谈谈你对java的理解

    这个题目是考察多个方面 但是要回答出关键点: 1.平台无关性 2.GC 3.语言特性.泛型.反射.lamda 4.面向对象 5.类库 6.异常处理

  10. 使用Auto Layout中的VFL(Visual format language)——代码实现自动布局

    本文将通过简单的UI来说明如何用VFL来实现自动布局.在自动布局的时候避免不了使用代码来加以优化以及根据内容来实现不同的UI. 一:api介绍 1.NSLayoutConstraint API NSL ...