-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1037.cpp
More file actions
44 lines (40 loc) · 749 Bytes
/
1037.cpp
File metadata and controls
44 lines (40 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// 1037.cpp
// 算法
//
// Created by 王怡凡 on 2017/8/22.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include <stdio.h>
#include<algorithm>
using namespace std;
const int maxn = 100010;
int ac[maxn],ap[maxn];
int nc,np;
int main() {
scanf("%d",&nc);
int i,ans=0;
for(i=0;i<nc;i++) {
scanf("%d",&ac[i]);
}
scanf("%d",&np);
for(i=0;i<np;i++) {
scanf("%d",&ap[i]);
}
sort(ac,ac+nc);
sort(ap,ap+np);
i=0;
int j=0;
while(i<nc&&j<np&&ac[i]<0&&ap[j]<0) {
ans += ac[i]*ap[j];
i++;
j++;
}
i=nc-1,j=np-1;
while(i>=0&&j>=0&&ac[i]>0&&ap[j]>0) {
ans += ac[i]*ap[j];
i--;
j--;
}
printf("%d",ans);
}