2019-12-23
14:54:40
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
const int MAX_LEN = 2004;
int main(){
double temp1[MAX_LEN]={0};
double temp2[MAX_LEN]={0};
int tem1;
cin>>tem1;
for(int i =0;i<tem1;++i){
int fir;
double sec;
cin>>fir;
cin>>sec;
temp1[fir] = sec;
}
int tem2;
scanf("%d",&tem2);
for(int i=0;i<tem2;++i){
int fir = 0;
double sec = 0;
cin>>fir;
cin>>sec;
temp2[fir] = sec;
}
double temp3[MAX_LEN] = {0};
int count = 0;
for(int i =MAX_LEN;i>=0;--i){
for(int j=MAX_LEN;j>=0;--j){
if(temp1[i]==0){
break;
}
else{
if(temp2[j]!=0){
//count++;
temp3[j+i] += (temp1[i]*temp2[j]);
}
}
}
}
for(int i=MAX_LEN;i>=0;--i){
if(temp3[i]!=0&&i!=MAX_LEN){
count++;
}
}
cout<<count;
for(int i=MAX_LEN;i>=0;--i){
if(temp3[i]!=0&&i!=MAX_LEN){
printf(" %d %.1f",i,temp3[i]);
}
}