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 ...
随机推荐
- EJB2的配置
1. ejb-jar.xml <?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns=&q ...
- 语音行业技术领先者Nuance诚招ASR/NLP研发工程师和软件工程师
Nuance is a leading provider of voice and language solutions for businesses and consumers around the ...
- SQLite_安装
SQLite -安装 zero-configuration SQLite闻名的特性,这意味着不需要复杂的设置或管理.本章将带你通过设置SQLite的过程在Windows.Linux和Mac OS X. ...
- SQLite -语法
SQLite -语法 SQLite是紧随其后的是独特的组称为语法的规则和指导方针.本教程为您提供了快速启动和SQLite的清单的所有基本SQLite语法. 大小写敏感性 注意重要的一点是,SQLite ...
- Node.js fs文件系统模块
一.读取文件几个步骤 1.先引入fs文件系统模块 2.使用readfile 或 readFileSync 注意点:它们的回调函数有两个参数,第一个是err,第二个是data,得到的data是buffe ...
- JDK的4种引用类型
在java中,大致有以下几种引用类型,强引用(StrongReference).软引用(SoftReference).弱引用(WeakReference).虚引用(PhantomReference) ...
- phpstudy里升级mysql版本到5.7
phpstudy里没有地方可以设置mysql数据库,很多人都疑惑在phpstudy里怎么升级mysql数据库版本,本文就教你如何在phpstudy中升级mysql的版本. PhpStudy集成环境中的 ...
- 如何在Python中显式释放内存?
根据Python官方文档,您可以强制垃圾收集器释放未引用的内存gc.collect().例: import gc gc.collect() 所属网站分类: python高级 > 综合&其 ...
- Centos 虚拟机 和宿主机 文件共享
我虚拟机下安装的是一个命令行式的centos ,想要把虚拟机里面的源文件移到宿主机上.于是我就想着搞一个文件共享. 网上有很多办法,比如Samba .ftp之类的.我选择了vmware自带的文件共享功 ...
- [数据结构]C#基于数组实现泛型顺序表
前方预警,只完成了顺序表的插入/删除/查找. 错误代码示例: /// <summary> /// 查找顺序表第i个位置的元素 /// 在显示情况中,我们更常用下标 /// </sum ...