PATA1037题解

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> coupons[2];
vector<int> product[2];
int main() {
int n, temp, k = 0, res = 0;
cin >> n;
for(int i = 0; i < n; i++) {
cin >> temp;
if(temp < 0) coupons[0].push_back(temp);
else coupons[1].push_back(temp);
}
cin >> n;
for(int i = 0; i < n; i++) {
cin >> temp;
if(temp < 0) product[0].push_back(temp);
else product[1].push_back(temp);
}
sort(coupons[0].begin(), coupons[0].end());
sort(coupons[1].begin(), coupons[1].end(), greater<int>() );
sort(product[0].begin(), product[0].end());
sort(product[1].begin(), product[1].end(), greater<int>() );
int len0 = coupons[0].size(), len1 = coupons[1].size();
int len2 = product[0].size(), len3 = product[1].size();
while(k < len0 && k <len2) {
res += coupons[0][k] * product[0][k];
k++;
}
k = 0;
while(k < len1 && k <len3) {
res += coupons[1][k] * product[1][k];
k++;
}
cout << res << endl;
}

转载于:https://www.cnblogs.com/dcklm/p/10348577.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值