Under construction

Still being built. Things may change

Clarissa's Conical Cannolis

Time limit5sMemory limit1024 MB

Summary
Given a cone's base diameter, slant height, dough disk radius, and target overlap, find the height above the base where the dough's bottom edge should sit.
Level

Medium6 of 10

Topics
Geometry, Math, Binary search
Solved
No attempts yet

Statement

Clarissa is developing a new dessert. It is a conical pastry filled with fruit, and it may also contain a creamy filling. Clarissa plans to wrap a circular disk of dough around a greased metal cone with a slight overlap, then cook it on the cone to form the shell (Figure 2).

Clarissa has had several metal cones made, each with a different base diameter D and slant height S (Figure 1). In Figure 1, D is the base diameter, H is the cone height, and S is the slant height. Figure 3 shows the other side of the cone and the overlap O.

Clarissa wants to test different dough recipes and cooking methods on each cone. The overlap O must be accurate. If it is too small, the shell is weak. If it is too large, the dough in the overlap is undercooked.

Clarissa wants an app where she enters the diameter D, the slant height S, the dough disk radius r, and the desired overlap O. The app returns the distance B above the base of the cone where the bottom of the dough should sit to get the desired overlap (Figure 4). She can mark this distance on the cone to make wrapping easier. This program is the core of the app. All values are in inches. Round B to the nearest tenth of an inch.

If the dough disk is so large that it overlaps too much at every position, output -1.0 (Figure 5). If the disk radius is too small, or the cone diameter is too large, so that the overlap is still insufficient with the top of the disk at the cone point, output -2.0 (Figure 6). In both cases, the app displays an error message.

Input

One line contains four space-separated decimal double precision floating point values D, S, r, and O. They satisfy 1.0≤D≤S≤161.0 \le D \le S \le 16, 2.0≤r≤S/22.0 \le r \le S/2, and 0.1≤O≤1.00.1 \le O \le 1.0.

Output

One line containing the base distance B, rounded to one decimal place. If the radius is too large and the disk overlaps too much at every position, output -1.0. If the disk radius is too small, or the cone diameter is too large, so that the overlap is insufficient even with the top of the disk at the cone point, output -2.0.

Examples3

  1. Example 1

    Input
    8 12 5 0.5
    
    Expected output
    1.5
    
  2. Example 2

    Input
    5 12 5 0.5
    
    Expected output
    -1.0
    
  3. Example 3

    Input
    11 12 5 0.5
    
    Expected output
    -2.0