This page is still under construction.

Parts of this page are still being built. What you see may change.

MapleStory

Time limit2sMemory limit1024 MB

Summary
Given N hunting grounds with entry experience thresholds and per-minute rates, plus travel times, find the maximum experience obtainable within T minutes.
Level

Hard8 of 10

Topics
Dynamic programming, Shortest path, Greedy, Graph
Solved
No attempts yet

Problem

Sangwon will play MapleStory during winter break. Since he will be busy once the semester starts, he wants to gain as many levels as possible during the break.

MapleStory has many hunting grounds. Each hunting ground has various characteristics such as the minimum level required to enter, the terrain, the monster level, the number of monsters, and burning. Since experience is what matters most to Sangwon, he simplified each hunting ground to its minimum experience required to enter and the experience gained per 11 minute. After he starts hunting, every minute he decides whether to keep hunting at his current ground or move to another ground. Sangwon spent all his money on cosmetic items and cannot teleport, so he walks between hunting grounds. He cannot hunt while moving between grounds, so he gains no experience then.

Since his character starts with 00 experience, he chooses one of the hunting grounds whose minimum experience required to enter is 00 and starts hunting there. Report the maximum experience Sangwon can gain during the break.

Input

The first line gives the number of hunting grounds NN (1≤N≤2001 \le N \le 200) and the length of the break in minutes TT (1≤T≤1 0001 \le T \le 1\,000).

The next NN lines give the characteristics of the ii-th hunting ground: the minimum experience required to enter cic_i and the experience gained per 11 minute eie_i. (0≤ci,ei≤1 000 0000 \le c_i, e_i \le 1\,000\,000)

The next NN lines give the time required to move between hunting grounds. The jj-th number in the ii-th line is ti,jt_{i,j}, the time in minutes required to move from hunting ground ii to hunting ground jj and enter it. (1≤ti,j≤1 0001 \le t_{i,j} \le 1\,000, ti,j=tj,it_{i,j}=t_{j,i}, ti,i=0t_{i,i}=0)

There is always at least one hunting ground whose minimum experience required to enter cic_i is 00.

Output

Print the maximum experience Sangwon can gain during the break.

Examples1

  1. Example 1

    Input
    2 10
    0 10
    50 100
    0 2
    2 0
    
    Expected output
    350