题意:

输入一个正整数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. PyCharm安装及汉化设置为中文(附汉化包)

    下载:https://www.jetbrains.com/pycharm/download/#section=windows 下载社区版免费 双击运行安装程序 Next 选择安装路径安装 创建桌面快捷 ...

  2. Cosmetic Bottles-Cosmetic Packaging Purpose: 5 Things

    Packaging in the cosmetics industry is based on in-depth research. And how it helps to win the edge ...

  3. Raid 10配置流程(五块磁盘)

    Raid 10配置流程(五块磁盘) 1.在虚拟机中再添加5块硬盘.  2.使用mdadm命令创建raid10,名称为“/dev/md0” -C代表创建操作,-v显示创建过程,-a yes检查RAID名 ...

  4. vscode git连接github

    上一篇文章中介绍了vscode中git的简单使用方法vscode git的简单使用 上次只讲到了本地库的创建,这次说明下怎么push到github上 首先需要有一个github的账号  github官 ...

  5. HTML5 canvas自制画板

    找到一个画板的插件,很好用,点击下载  ,页面很简单,但是呢,貌似不适用于手机端,,,

  6. TCP协议下的服务端并发,GIL全局解释器锁,死锁,信号量,event事件,线程q

    TCP协议下的服务端并发,GIL全局解释器锁,死锁,信号量,event事件,线程q 一.TCP协议下的服务端并发 ''' 将不同的功能尽量拆分成不同的函数,拆分出来的功能可以被多个地方使用 TCP服务 ...

  7. RTU license

    Right to Use (RTU) licensing is a model in which licenses are not tied to a unique device identifier ...

  8. 未来的flags

    完了大致一扫..... (1)P,NP,NPC,NP-Hard 二分图(2)二分图的判定 Tarjan(3)有向图的Tarjan算法(4)无向图的Tarjan算法 (5)A*算法 环套树(6)环套树的 ...

  9. 13,viewport

    set viewport:~是一种函数,功能是为图形输出设置当前视口. 怎样处理移动端1px被渲染成2px的问题(略)

  10. 【PAT甲级】1073 Scientific Notation (20 分)

    题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...