Posted on

Submission

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

const int MAXN = 1001;
double terms[MAXN];
int main() {
    int n; cin >> n;
    int power;
    double coeff;
    int count = 0;
    for(int i = 0; i < n; ++i) {
        cin >> power >> coeff;
        terms[power] += coeff;
    }
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> power >> coeff;
        terms[power] += coeff;
    }

    for(int i = 0; i < MAXN; ++i) {
        if(abs(terms[i]) > 1e-9) {
            count++;
        }
    }
    cout << count;
    for(int i = MAXN - 1; i >= 0 ; --i) {
        if(abs(terms[i]) > 1e-9) {
            cout << fixed << setprecision(1);
            cout << " " << i << " "  << terms[i];
        }
    }

    return 0;
}

References

  1. https://www.liuchuo.net/archives/1890

Leave a Reply

Your email address will not be published. Required fields are marked *