给两个序列,一一对应相乘,求最大和。

0不算数,输入时按正负共分为4个数组。

 #include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=;
int coupon1[maxn],coupon2[maxn];
int product1[maxn],product2[maxn];
bool cmp(int a,int b){
return a>b;
}
int main(){
int n,m,c1=,c2=,p1=,p2=;
long long cx,px,ans=;
scanf("%d", &n);
for(int i=;i<n;i++){
scanf("%lld",&cx);
if(cx>=) {
coupon1[c1++]=cx;
}
else {
coupon2[c2++]=cx;
}
}
scanf("%d",&m);
for(int i=;i<m;i++){
scanf("%lld",&px);
if(px>=) {
product1[p1++]=px;
}
else {
product2[p2++]=px;
}
}
sort(coupon1,coupon1+c1,cmp);
sort(coupon2,coupon2+c2);
sort(product1,product1+p1,cmp);
sort(product2,product2+p2);
for(int i=;i<c1;i++){
ans+=coupon1[i]*product1[i];
}
for(int i=;i<c2;i++){
ans+=coupon2[i]*product2[i];
}
printf("%lld",ans);
return ;
}

A1037的更多相关文章

  1. A1037. Magic Coupon

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

  2. A1037 Magic Coupon (25 分)

    一.技术总结 这也是一个贪心算法问题,主要在于想清楚,怎么解决输出和最大,两个数组得确保符号相同位相乘,并且绝对值尽可能大. 可以用两个vector容器存储,然后排序从小到大或是从大到小都可以,一次从 ...

  3. PAT甲级——A1037 Magic Coupon

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

  4. 1037 Magic Coupon (25 分)

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

  5. 1.21 贪心入门上午PAT例题题解

    1.B1023 #include<cstdio> int a[10]; int main() { for(int i=0;i<=9;i++) { scanf("%d&quo ...

  6. PAT_A1037#Magic Coupon

    Source: PAT A1037 Magic Coupon (25 分) Description: The magic shop in Mars is offering some magic cou ...

  7. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. golang 时间戳 时间格式化 获取当前时间 timestamp 计算时间差

    获取当前时间 func Now func Now() Time 1 Now returns the current local time. func (Time) UTC func (t Time) ...

  2. Windows下Git服务端和客户端的搭建

    1.服务器端的搭建 本人使用的是一款带源码的工具:bonobogitserver,对应的网址为:https://bonobogitserver.com/ 具体操作方式如下: 1.打开网址,下载最新版本 ...

  3. C#网络编程(一)基础篇

    简介: C#网络编程API包含在System.Net和System.Net.Sockets命名空间下,大部分网络操作都可以在其中找到相应的类来实现:包括Socket的创建和连接,网络流收发方法的封装, ...

  4. Homebrew 安装 MySQL

    安装 Homebrew brew doctor 确认 brew 在正常工作 brew update 更新包 brew install mysql 安装 MySQL ​ ==> Downloadi ...

  5. Maven 阿里源

    由于一些不可抗拒因素,在使用 maven 的时候我们不得不需要改变一些设置,以加快我们的下载速度. ​ 仓库配置 ​ 在maven的settings.xml文件里的mirrors节点,添加如下子节点: ...

  6. 关于memcpy的实现

    今天去面试,面试官出了一个关于memcpy的函数原型的实现的问题,本来这个问题是很简单的,但是不知道当时怎么脑子一抽竟然写错了,真是”累觉不爱”了.感觉这份工作算是泡汤了,算了事情发生了,错过了也就错 ...

  7. pythone 请求响应字典

    _RESPONSE_STATUSES = { # Informational 100: 'Continue', 101: 'Switching Protocols', 102: 'Processing ...

  8. Web项目打成war包部署到tomcat时报MySQL Access denied for user 'root'@'localhost' (using password: YES)错误解决方案

    Web项目使用使用root账号root密码进行部署,通过Eclipse加载到Tomcat服务器可以发布成功,打成war包放到tomcat的webapps目录无法发布成功,报错: jdbc.proper ...

  9. Django实战(一)之简单Demo

    菜鸟教程上Django安装可供参考: 参考链接: http://www.runoob.com/django/django-install.html 菜鸟教程上如果不行的话,下面博客网址可以供参考 Li ...

  10. JavaScript(jQuery)中的事件委托

    一:什么是事件委托? 事件委托是利用事件冒泡,只指定一个事件处理程序来管理某一类型的所有事件. 二:为什么要用事件委托? 1.在JavaScript中添加到页面上的事件处理程序的个数直接关系到页面的整 ...