题1009

版权声明:// Copyright © 2018年 Coding18. All rights reserved. https://blog.csdn.net/Coding18/article/details/85914347
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
float a[1100] = {0},b[2500] = {0};
int main()
{
	int m,n,k;
	float t;
	scanf("%d",&m);
	for(int i = 0; i < m; i++){
		scanf("%d",&k);
		scanf("%f",&a[k]);
	}
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&k);
		scanf("%f",&t);
		for(int j = 1005; j >= 0; j--)
		{
			if(a[j] != 0)
			b[j+k] += t * a[j];
		}
	}
	int total = 0;
	for(int i = 0; i < 2010; i++){
		if(b[i] != 0) total++;
	}
	printf("%d",total);
	for(int i = 2010; i >= 0; i--){
		if(b[i] != 0){
			printf(" %d %.1f",i,b[i]);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Coding18/article/details/85914347