Don't Hunger Together

시간 제한4초메모리 제한2048 MB

요약
각 턴의 낮에 구한 음식은 유통기한이 있는 밤까지 소비해야 하며, 모든 플레이어가 살아남을 수 있는 하루 1인당 최대 식량을 구하거나 불가능하면 -1을 출력한다.
난이도

어려움10점 중 8점

유형
그리디, 이분 탐색, 누적 합
정답자
아직 제출이 없습니다

문제

Ashley and Brandon are designing a survival video game called Don't Hunger Together. The game works as follows:

The game proceeds as a number of turns. Each turn consists of a day followed by a night. Several players have to survive for many turns in the wilderness. They collect food in the daytime and eat at night. During the daytime, they can scavenge up to a maximum amount of food, and the food found on that day must be eaten by some night in the future. Any leftover such food goes bad and is inedible. Each night, every player must eat a certain quantity of food, otherwise they will die of hunger. They win if every player is able to eat enough food on each of the nights.

Ashley and Brandon have designed a scenario and the last thing they need to do is pick the quantity of food that each player must eat every night. They wish to know the maximum possible value of this quantity, which must be positive. However, if the game is not winnable for any positive value, please let Ashley and Brandon know the scenario is impossible!

입력

The first line of input contains two integers nn (1≤n≤1061 \le n \le 10^6) and kk (1≤k≤391 \le k \le 39), where nn is the number of turns in the game, and kk is the number of players. The turns are numbered from 11 to nn.

Each of the next nn lines contains two integers qq (0≤q≤1090 \le q \le 10^9) and ff (i≤f≤ni \le f \le n), where qq is the quantity of food that can be scavenged on that turn's day, ff is the future turn's night after which the food goes bad, where ii is the turn number. The turns are listed in order from 11 to nn.

출력

Output a single real number, which is the maximum positive quantity of food each player can eat on each night and still survive the scenario, or −1-1 if the situation is not winnable for any positive value. Any answer within an absolute or relative error of 10−910^{-9} will be accepted.

예제3

  1. 예제 1

    입력
    2 1
    4 2
    3 2
    
    예상 출력
    3.5
    
  2. 예제 2

    입력
    2 2
    4 1
    3 2
    
    예상 출력
    1.5
    
  3. 예제 3

    입력
    1 17
    0 1
    
    예상 출력
    -1