-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathA1009.cpp
More file actions
43 lines (41 loc) · 722 Bytes
/
A1009.cpp
File metadata and controls
43 lines (41 loc) · 722 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
#include <cstdio>
#include <cstdlib>
using namespace std;
const double E = 1e-15;
int main(){
double a[1010] = {0.0}, b[1010] = {0.0}, c[2010] = {0.0};
int k, n;
double x;
scanf("%d", &k);
for(int i = 0; i < k; ++i){
scanf("%d %lf", &n, &x);
a[n] = x;
}
scanf("%d", &k);
for(int i = 0; i < k; ++i){
scanf("%d %lf", &n, &x);
b[n] = x;
}
for(int i = 0; i < 1001; ++i){
for(int j = 0; j < 1001; ++j){
if(a[i] != 0 && b[j] != 0){
n = i + j;
x = a[i] * b[j];
c[n] += x;
}
}
}
int count = 0;
for(int i = 0; i <= 2000; ++i){
if(c[i] != 0){
++count;
}
}
printf("%d", count);
for(int i = 2000; i >= 0; --i){
if(c[i] != 0){
printf(" %d %.1f", i, c[i]);
}
}
return 0;
}