다음 문제를 해결하기 위해 C++ 프로그램을 작성하고 있습니다.

```

문제

George has won the lottery and, being a nice guy, has decided to spread the wealth around. However, monetary gifts can be taxed once they get over a certain size—the amount of tax depends on how much his friends have earned that year.

The amount of tax paid depends on tax bands. The bands start at zero. Each one takes a certain cut of income from the range of pre-tax income it covers. The final tax band applies to all income above its lower bound.

George is a savvy fellow and knows the number of tax bands, the amount of money each friend has earned and the amount he wants each friend to walk away with.

How much should George give to each friend before tax?
입력

    One line containing an integer B (1 ≤ B ≤ 20): the number of tax bands.
    B further lines, each containing two real numbers: si (0 < si ≤ 106): the size in pounds of the ith tax band, and pi (0 ≤ pi ≤ 100): the percentage taxation for that band.
    One line containing a real number P (0 ≤ P ≤ 99.999): the percentage tax on all income above other bands.
    One line containing an integer F, (0 < F ≤ 20): the number of friends George wants to pay.
    F further lines, each containing two real numbers ej and mj (0 ≤ ej ≤ 106, 0 < mj ≤ 106): the amount of money the jth friend has earned, and the amount of money they should receive after tax respectively.

Tax bands will be given in increasing order.
출력

    F lines, one for each friend specified in the input and in the same order.

Each line should contain one real number: the amount of money George will give to his friend, in order to arrive at the correct amount after they have paid tax.
All output must be accurate to an absolute or relative error of at most 10−6.
```
다음과 같이 코드를 작성했습니다.

```
#include <bits/stdc++.h>
using namespace std;

double s[21], p[21];
double P;
int B, F;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> B;
    for (int i = 0; i < B; i++) {
        cin >> s[i] >> p[i];
    }

    cin >> P;

    s[B] = 1e20; p[B] = P;

    cin >> F;
    for (int i = 0; i < F; i++) {
        double e, m;
        cin >> e >> m;

        double answer = 0;
        for (int i = 0; i <= B; i++) {
            if (e > 0) {
                if (e < s[i]) {
                    if (m <= (s[i] - e) * (100.0 - p[i]) / 100.0) {
                        answer += min(m, s[i] - e) * 100.0 / (100.0 - p[i]);
                        m -= min(m, s[i] - e);
                    } else {
                        answer += min(m, s[i] - e);
                        m -= (s[i] - e) * (100.0 - p[i]) / 100.0;
                    }
                }

                e -= s[i];
            } else {
                if (m <= s[i] * (100.0 - p[i]) / 100.0) {
                    answer += min(m, s[i]) * 100.0 / (100.0 - p[i]);
                    m -= min(m, s[i]);
                } else {
                    answer += min(m, s[i]);
                    m -= s[i] * (100.0 - p[i]) / 100.0;
                }
            }
        }

        cout.precision(6);
        cout << fixed << answer << '\n';
    }

    return 0;
}
```

그런데 다음 입력케이스에서 잘못된 출력을 하는 것 같습니다.

```
3
4750.50 0
8000 20
10000 40
60
3
0 10000
10000 5000
15000 5000
```

문제 상황을 분석하고, 주어진 코드를 사려깊게 분석한 뒤, 잘못된 부분을 수정해주세요.