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

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. SVN global ignore pattern

    *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store */bin */ ...

  2. magento2常见的命令

    常见的命令如下: php bin/magento list    查看所有命令列表 ----------------------------moudule相关的参数------------------ ...

  3. August 06th 2017 Week 32nd Sunday

    No words are necessary between two loving hearts. 两颗相爱的心之间不需要言语. No, I don't think so. Words may be ...

  4. December 18th 2016 Week 52nd Sunday

    May your love soar on the wings of a dove in flight. 愿你的爱乘着飞翔中的白鸽,展翅高飞. May my life soar on the wing ...

  5. vue项目出现的错误汇总

    报错一: expected "indent", got "!" 通过vue-cli创建的项目,不需要在webpack.base.conf.js中再手动配置关于c ...

  6. 【[JSOI2009]火星藏宝图】

    这里是\(sb\)的\(O(nm)\)做法 上一篇题解里写的\(O(nm)\)做法并没有看懂,我真是好菜啊 这是一个用了斜率优化,但是复杂度仍然是\(O(nm)\)的做法 我们还是先写出简单的\(dp ...

  7. 包不包含__declspec(dllimport)的判定

    按照MSDN说明,当链接dll的导出函数时,只需要包含头文件和lib,__declspec(dllimport)修饰符不是必须的,但加上该修饰能使导出函数的调用效率更高.那么,究竟原因是什么? 不使用 ...

  8. 用ReentrantLock和Condition实现线程间通信

    在Java多线程中,除了使用synchronize关键字来实现线程之间的同步互斥,还可以使用JDK1.5中新增的RetrantLock类来实现同样的效果.RetrantLock类的扩展功能也更加强大, ...

  9. Spring(四)之Bean生命周期、BeanPost处理

    一.Bean 生命周期 Spring bean的生命周期很容易理解.当bean被实例化时,可能需要执行一些初始化以使其进入可用状态.类似地,当不再需要bean并从容器中移除bean时,可能需要进行一些 ...

  10. python -- 将string转换成dict的方法

    装载自:http://smilejay.com/2014/10/convert_string_to_dict_python/ 我将数据库连接相关的一些用户名/密码/host/port等各种东西作为一个 ...