传送门:http://codeforces.com/problemset/problem/1106/E
E. Lunar New Year and Red Envelopes
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Lunar New Year is approaching, and Bob is going to receive some red envelopes with countless money! But collecting money from red envelopes is a time-consuming process itself.
Let's describe this problem in a mathematical way. Consider a timeline from time 11 to nn. The ii-th red envelope will be available from time sisi to titi, inclusive, and contain wiwi coins. If Bob chooses to collect the coins in the ii-th red envelope, he can do it only in an integer point of time between sisi and titi, inclusive, and he can't collect any more envelopes until time didi (inclusive) after that. Here si≤ti≤disi≤ti≤di holds.
Bob is a greedy man, he collects coins greedily — whenever he can collect coins at some integer time xx, he collects the available red envelope with the maximum number of coins. If there are multiple envelopes with the same maximum number of coins, Bob would choose the one whose parameter dd is the largest. If there are still multiple choices, Bob will choose one from them randomly.
However, Alice — his daughter — doesn't want her father to get too many coins. She could disturb Bob