// File: hcoona[P]POJ-Solutions/P1018.cpp
// Function: POJ::P1018::Solve(std::vector<std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>, std::allocator<std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>> const&) const
double P1018::Solve(const vector<vector<pair<int, int> > > &deviceData) const
    {
        map<int, int> bandwidthToPrice;
        for (auto it = deviceData.begin(); it != deviceData.end(); it++) {
            for (auto iit = it->begin(); iit != it->end(); iit++) {
                bandwidthToPrice[iit->first] = 0;
            }
        }

        const int INVALID_PRICE = -1;
        for (auto dit = deviceData.begin(); dit != deviceData.end(); dit++) {
            for (auto it = bandwidthToPrice.begin(); it != bandwidthToPrice.end(); it++) {
                if (it->second != INVALID_PRICE) {
                    auto beginPosition = dit->begin();
                    auto endPosition = upper_bound(
                        beginPosition,
                        dit->end(),
                        *it,
                        PredByFirstGt<int, int>);
                    if (beginPosition == endPosition) {
                        it->second = INVALID_PRICE;
                    } else {
                        it->second += min_element(beginPosition, endPosition, PredBySecondLt<int, int>)->second;
                    }
                }
            }
        }
        
        double maxBperP = 0.0;
        for (auto it = bandwidthToPrice.begin(); it != bandwidthToPrice.end(); it++) {
            auto BperP = static_cast<double>(it->first) / static_cast<double>(it->second);
            maxBperP = max(maxBperP, BperP);
        }
        return maxBperP;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2ea0
movq -0x10(%rbp), %rdi
callq 0x2ec0
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2f30
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2ef0
testb $0x1, %al
jne 0x263c
jmp 0x26e5
leaq -0x48(%rbp), %rdi
callq 0x2f60
movq %rax, %rdi
callq 0x2f80
movq %rax, -0x58(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2f60
movq %rax, %rdi
callq 0x2ff0
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2fb0
testb $0x1, %al
jne 0x2679
jmp 0x26cf
leaq -0x58(%rbp), %rdi
callq 0x3100
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x3020
movq %rax, -0x120(%rbp)
jmp 0x2697
movq -0x120(%rbp), %rax
movl $0x0, (%rax)
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x3120
movq %rax, -0x78(%rbp)
jmp 0x2651
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x33e0
jmp 0x29e8
jmp 0x26d1
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x3160
movq %rax, -0x80(%rbp)
jmp 0x2619
movl $0xffffffff, -0x84(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
callq 0x2ec0
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2f30
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2ef0
testb $0x1, %al
jne 0x272b
jmp 0x28ea
leaq -0x40(%rbp), %rdi
callq 0x31a0
movq %rax, -0xa0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3200
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x31d0
testb $0x1, %al
jne 0x2767
jmp 0x28ce
leaq -0xa0(%rbp), %rdi
callq 0x3230
cmpl $-0x1, 0x4(%rax)
je 0x28b2
leaq -0x90(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x2f60
movq %rax, %rdi
callq 0x2f80
movq -0x130(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
callq 0x2f60
movq %rax, %rdi
callq 0x2ff0
movq %rax, -0xc8(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x32b0
movq %rax, %rdx
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
leaq -0x21c(%rip), %rcx      # 0x25d0
callq 0x3250
movq %rax, -0x128(%rbp)
jmp 0x27fa
movq -0x128(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x32d0
testb $0x1, %al
jne 0x2821
jmp 0x2836
leaq -0xa0(%rbp), %rdi
callq 0x3230
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
jmp 0x28b0
movq -0xb0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
leaq 0x199(%rip), %rdx       # 0x2a00
callq 0x3310
movq %rax, -0x138(%rbp)
jmp 0x2875
movq -0x138(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3100
movl 0x4(%rax), %eax
movl %eax, -0x13c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3230
movl -0x13c(%rbp), %ecx
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x28b2
jmp 0x28b4
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
callq 0x3360
movq %rax, -0xe8(%rbp)
jmp 0x273b
jmp 0x28d0
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
callq 0x3160
movq %rax, -0xf0(%rbp)
jmp 0x26ff
xorps %xmm0, %xmm0
movsd %xmm0, -0xf8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x31a0
movq %rax, -0x100(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3200
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x31d0
testb $0x1, %al
jne 0x2931
jmp 0x29be
leaq -0x100(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x3230
movq -0x158(%rbp), %rdi
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, -0x150(%rbp)
callq 0x3230
movsd -0x150(%rbp), %xmm0
cvtsi2sdl 0x4(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x110(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x33a0
movq %rax, -0x148(%rbp)
jmp 0x2991
movq -0x148(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0xf8(%rbp)
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
callq 0x3360
movq %rax, -0x118(%rbp)
jmp 0x2905
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x33e0
movsd -0x160(%rbp), %xmm0
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x2150
nopw %cs:(%rax,%rax)