题意:

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

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
long long a[],b[];
long long c[],d[];
int cnta,cntb,cntc,cntd;
int main(){
int n,m;
cin>>n;
long long x;
for(int i=;i<=n;++i){
cin>>x;
if(x>)
a[++cnta]=x;
else if(x<)
b[++cntb]=x;
}
cin>>m;
for(int i=;i<=m;++i){
cin>>x;
if(x>)
c[++cntc]=x;
else if(x<)
d[++cntd]=x;
}
long long ans=;
sort(a+,a++cnta);
sort(b+,b++cntb);
sort(c+,c++cntc);
sort(d+,d++cntd);
for(int i=;i<=min(cntb,cntd);++i)
ans+=b[i]*d[i];
for(int i=cnta,j=cntc;i&&j;--i,--j)
ans+=a[i]*c[j];
cout<<ans;
return ;
}

【PAT甲级】1037 Magic Coupon (25 分)的更多相关文章

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

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

  2. PAT 甲级 1037 Magic Coupon

    https://pintia.cn/problem-sets/994805342720868352/problems/994805451374313472 The magic shop in Mars ...

  3. 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, ...

  4. 1037 Magic Coupon (25分)

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

  5. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

  6. PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)

    1146 Topological Order (25 分)   This is a problem given in the Graduate Entrance Exam in 2018: Which ...

  7. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  8. PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)

    1063 Set Similarity (25 分)   Given two sets of integers, the similarity of the sets is defined to be ...

  9. PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)

    1059 Prime Factors (25 分)   Given any positive integer N, you are supposed to find all of its prime ...

随机推荐

  1. Python学习之面向对象进阶

    面向对象进阶当然是要谈谈面向对象的三大特性:封装.继承.多态 @property装饰器 python虽然不建议把属性和方法都设为私有的,但是完全暴露给外界也不好,这样,我们给属性赋值的有效性九无法保证 ...

  2. centos7下Maven Java selenium3环境搭建

    centos7下Maven Java selenium3环境搭建 一.Jdk安装 我这里用的是open-jdk. [adawang@localhost src]$ sudo yum search op ...

  3. 开源协议:LGPL协议、OSGi协议

    本文介绍开源的协议. LGPL 是 GNU Lesser General Public License (GNU 宽通用公共许可证)的缩写形式,旧称 GNU Library General Publi ...

  4. HDU 1069 Monkey and Banana(线性DP)

    Description   A group of researchers are designing an experiment to test the IQ of a monkey. They wi ...

  5. Spring_第一个Spring入门案例IOC

    今天我们来写我们的第一个spring 第一步 建立一个java project 第二步 添加我们的五个jar文件 第三步 在项目中建立一个com.zk.spring包 第四步 建立我们的userser ...

  6. oracle常见的函数

    1.字符函数 -- initcap函数只针对英文 select * from tb_user where user_name = initcap('张三'); -- ltrim 左剪切 select ...

  7. Windows 10下一步一步创建 Scrapy框架的项目

    此文是本人的学习笔记,网上搜索了很多资料,也走了一些弯路,记录下安装的过程,以便日后回顾 1.安装Anaconda3,安装时默认选项 2.装完Anaconda3后,打开系统变量在path路径下增加An ...

  8. SQL表名,应该用表对应资源对象的复数形式还是单数形式

    原文:http://blog.csdn.net/lizeyang 问题 SQL表名,应该用表对应资源对象的复数形式还是单数形式.例如一个用户表,表名是用user还是users更合适呢?   精华回答 ...

  9. MYSQL双查询错误1

    一.基础知识 开始讲解MYSQL双查询错误之前,我们先了解一下双查询语句以及需要使用到的几个数据库函数和GROUP BY语句 1. 双查询语句 先了解一下什么是子查询,子查询就是嵌入第一层select ...

  10. Centos7下载和安装教程

    https://blog.csdn.net/qq_42570879/article/details/82853708 阿里下载64bit镜像:http://mirrors.aliyun.com/cen ...