Under construction

Still being built. Things may change

Giant Cover

Time limit1sMemory limit128 MB

Summary
Given axis-aligned boxes on a rectangular campus, find the minimum surface area of a convex solid above the ground that covers all boxes and is anchored to the campus boundary.
Level

Hard9 of 10

Topics
Geometry, Math, Greedy, Implementation
Solved
No attempts yet

Problem

A student at the Lutjebroek University of Technology wants to cover every building on campus with one enormous translucent plastic sheet. Nobody in the area would need an umbrella after that, which cuts costs a lot.

The price of the sheet is proportional to its area, so the student wants the smallest cover possible. Write a program that computes that minimum area.

The campus terrain is flat and rectangular. Every building is a union of boxes standing on the ground, and boxes may overlap. The cover has to lie above all buildings and is fastened to the four sides of the campus at ground level.

The sheet is pulled tight, so the solid enclosed by the cover and the ground is convex. Report the area of the smallest cover that meets these conditions. The ground rectangle itself does not count toward that area.

Input

The first line contains the number of test cases. Each test case has the following format.

  • One line with four integers x1x_1, y1y_1, x2x_2, y2y_2 separated by spaces. The campus terrain is [x1,x2]×[y1,y2][x_1, x_2] \times [y_1, y_2], with −104≤x1<x2≤104-10^4 \le x_1 < x_2 \le 10^4 and −104≤y1<y2≤104-10^4 \le y_1 < y_2 \le 10^4.
  • One line with the integer nn, the number of boxes that form the buildings, where 0≤n≤4000 \le n \le 400.
  • nn lines. The iith of them holds five integers aia_i, bib_i, cic_i, did_i, hih_i separated by spaces, describing a box with footprint [ai,ci]×[bi,di][a_i, c_i] \times [b_i, d_i] and height hih_i above the ground. They satisfy x1≤ai<ci≤x2x_1 \le a_i < c_i \le x_2, y1≤bi<di≤y2y_1 \le b_i < d_i \le y_2 and 0<hi≤1040 < h_i \le 10^4.

Here [a,c]×[b,d][a, c] \times [b, d] is a Cartesian product, the rectangular area of all points (x,y)(x, y) with a≤x≤ca \le x \le c and b≤y≤db \le y \le d.

Output

For every test case, print the area of the smallest cover on one line, with four digits after the decimal point. Round the usual way: a digit is rounded up when the next digit is 5 or more, and rounded down otherwise.

Examples2

  1. Example 1

    Input
    3
    0 0 12 10
    0
    0 0 12 10
    1
    2 2 8 8 3
    0 0 12 10
    2
    2 4 10 8 3
    4 2 8 6 5
    
    Expected output
    120.0000
    169.7443
    203.7598
    
  2. Example 2

    Input
    2
    0 0 4 5
    1
    0 0 4 5 2
    -3 -4 3 4
    0
    
    Expected output
    56.0000
    48.0000