给两个序列,一一对应相乘,求最大和。
0不算数,输入时按正负共分为4个数组。
1 #include2 #include 16 scanf("%lld",&cx); 17 if(cx>=0) { 18 coupon1[c1++]=cx; 19 } 20 else { 21 coupon2[c2++]=cx; 22 } 23 } 24 scanf("%d",&m); 25 for(int i=0;i3 #include 4 using namespace std; 5 const int maxn=100010; 6 int coupon1[maxn],coupon2[maxn]; 7 int product1[maxn],product2[maxn]; 8 bool cmp(int a,int b){ 9 return a>b; 10 } 11 int main(){ 12 int n,m,c1=0,c2=0,p1=0,p2=0; 13 long long cx,px,ans=0; 14 scanf("%d", &n); 15 for(int i=0;i ){ ){ 26 scanf("%lld",&px); 27 if(px>=0) { 28 product1[p1++]=px; 29 } 30 else { 31 product2[p2++]=px; 32 } 33 } 34 sort(coupon1,coupon1+c1,cmp); 35 sort(coupon2,coupon2+c2); 36 sort(product1,product1+p1,cmp); 37 sort(product2,product2+p2); 38 for(int i=0;i ){ 39 ans+=coupon1[i]*product1[i]; 40 } 41 for(int i=0;i ){ 42 ans+=coupon2[i]*product2[i]; 43 } 44 printf("%lld",ans); 45 return 0; 46 }