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;
}

猜你喜欢

转载自www.cnblogs.com/dcklm/p/10348577.html