添加链接描述

#include<bits/stdc++.h>
using namespace std;
const int N=0.3e4+9;
map<int,double,greater<int>> arr,brr;
int mxa,mxb;
typedef pair<int,double> pii;
vector<pii>c,ans;
int main(){
    int n;
    cin>>n;
    
    for(int i=1;i<=n;i++){
        int z,x;
        // cin>>z>>x;
        scanf("%d%d",&z,&x);
        arr[z]=x;
        mxa=max(mxa,z);
    }
    cin>>n;
    for(int i=1;i<=n;i++){
        int z,x;
        // cin>>z>>x;
         scanf("%d%d",&z,&x);
        brr[z]=x;
        mxb=max(mxb,z);
    }
    // cout<<mxa<<":"<<mxb<<"\n";
    while(mxa>=mxb){
        double p=arr[mxa]/brr[mxb];//系数
        // cout<<arr[mxa]<<" "<<brr[mxb]<<"\n";
        int z=mxa-mxb;//指数
        if(abs(p)<0.05)p=0;
        //  cout<<z<<" "<<p<<"\n";
        if(p)
        c.push_back({z,p});
        for(auto it:brr){
            arr[it.first + z] -= it.second*p;
        }
        arr.erase(arr.begin());
        mxa=arr.begin()->first;
    }
    cout<<c.size();
    if(c.size()==0){
        cout<<" 0 0.0";
    }
    for(auto it:c){
        printf(" %d %.1lf",it.first,it.second);
    }
    for(int i=mxa;i>=0;i--){
        if(abs(arr[i])>=0.05){
            ans.push_back({i,arr[i]});
        }
    }
    cout<<"\n"<<ans.size();
    for(auto it:ans){
         printf(" %d %.1lf",it.first,it.second);
    }
    if(ans.size()==0){
        cout<<" 0 0.0";
    }

    return 0;
}