Somewhere Over the Rainbow
Time limit2sMemory limit512 MB
Given lower bounds a_x at n points, find the minimum sum of a strictly convex integer sequence with a_0 = a_m = 0, modulo 998244353.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Math, Greedy
- Solved
- No attempts yet
Problem
Time limit: 2000 ms. Memory limit: 512 MB.
You want to draw a rainbow. The rainbow can be represented as a sequence of integer heights that must satisfy the following constraints:
- (both endpoints are 0 meters above the horizon)
- for all (the rainbow is convex)
- for given pairs .
You also want the rainbow to take as little space as possible. Find the minimum possible value of . Since the answer may be very large, output it modulo 998244353.
Input
The first line contains two positive integers and (, ): the number of constraints and the length of the sequence.
Each of the next lines contains two integers () and (), which set the condition .
It is guaranteed that .
Output
Print one integer: the minimum value of modulo 998244353.
Hint
In the sample case, one optimal height sequence is .