PAT (Advanced Level) 1037. Magic Coupon (25)
简单题。
#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)的更多相关文章
- 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 ...
- 【PAT甲级】1037 Magic Coupon (25 分)
题意: 输入一个正整数N(<=1e5),接下来输入N个整数.再输入一个正整数M(<=1e5),接下来输入M个整数.每次可以从两组数中各取一个,求最大的两个数的乘积的和. AAAAAccep ...
- PAT 甲级 1037 Magic Coupon (25 分) (较简单,贪心)
1037 Magic Coupon (25 分) The magic shop in Mars is offering some magic coupons. Each coupon has an ...
- 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, ...
- PAT甲题题解-1037. Magic Coupon (25)-贪心,水
题目说了那么多,就是给你两个序列,分别选取元素进行一对一相乘,求得到的最大乘积. 将两个序列的正和负数分开,排个序,然后分别将正1和正2前面的相乘,负1和负2前面的相乘,累加和即可. #include ...
- 1037 Magic Coupon (25分)
The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, m ...
- 1037. Magic Coupon (25)
#include<iostream> #include<vector> #include<stdio.h> #include<algorithm> us ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
随机推荐
- win应用只允许单个实例运行,并将已运行实例窗口置顶
关键词:windows,c++,桌面应用,单个实例,窗口置顶 目标:1.判断本程序是否已有一个实例在运行.2.若有,则激活已在运行的实例(将其窗口置顶),并退出当前运行. 1.使用semaphore来 ...
- 【HEVC简介】ALF-Adative Loop Filter
由于HEVC在HM4.0之后,就把ALF去掉,所以ALF的介绍是基于AVS2. <HEVC标准介绍.HEVC帧间预测论文笔记>系列博客,目录见:http://www.cnblogs.com ...
- PHP一句话后门过狗姿势万千之传输层加工
既然木马已就绪,那么想要利用木马,必然有一个数据传输的过程,数据提交是必须的,数据返回一般也会有的,除非执行特殊命令. 当我们用普通菜刀连接后门时,数据时如何提交的,狗狗又是如何识别的,下面结合一个实 ...
- Hbase数据库简介
Hbase是基于Hadoop下分布式存储 数据库,列式存储.(https://www.imooc.com/video/17202) 动态的增加列,不像关系数据库需要提前定义好列. 关系数据库 ...
- 暑假集训 || 2-SAT
推荐论文:https://blog.csdn.net/zixiaqian/article/details/4492926 2-SAT问题是2判定性问题,给出n个集合,每个集合中有两个元素,两个元素之一 ...
- tensorflow-gpu install check
https://gist.github.com/mrry/ee5dbcfdd045fa48a27d56664411d41c#file-tensorflow_self_check-py-L16
- 无法读取配置节"system.web.extensions",因为它缺少节声明
设置 .Net Framework版本 v2.0.50727 要设置成 v4.0.30319
- [题解] cogs 2240 架设电话线路
http://cogs.pro:8080/cogs/problem/problem.php?pid=2240 与洛谷P2885几乎一致,https://www.luogu.org/problemnew ...
- sin_addr.s_addr和sin_addr.S_un.S_addr
sin_addr.s_addr和sin_addr.S_un.S_addr 先mark一下,等下写
- 同一SQL语句在PLSQL Developer与SQL * PLUS工具中执行结果不一致
背景 今天遇到如下问题,同一sql语句在PLSQL Developer与SQL*PLUS工具中执行结果不一致, sql语句如下 SELECT 'GROUPHEALTH_SEND_EMAIL' as i ...