

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
Atcoder 国には から の番号がついた 個の街と、 から の番号がついた 本の電車が走っています。
電車 は街 を時刻 に発車し、街 に時刻 に到着します。
正の整数 が与えられるので、 以上の整数 を以下の条件を満たすように定める方法のうち、 が最小になるものを求めてください。
- 条件: を満たす全ての組 について、「 かつ 」ならば「」
- すなわち、もともと乗り換え可能だった電車の組は、各電車 の発車時刻・到着時刻を 遅らせても乗り換え可能である
なお、 が最小になるような の定め方は一意であることが証明できます。
制約
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
出力
条件を満たし、和を最小化するような を、この順に空白区切りで出力せよ。
入力例 1Copy
3 6 15 1 2 10 20 1 2 20 30 2 3 25 40 2 3 35 50 3 1 15 30 3 1 45 60
出力例 1Copy
0 10 0 0 5
街 から へ行く電車 の到着が 遅れ、時刻 になりました。
街 での電車 から への乗り換えのため、電車 の発車時刻を 遅らせて、時刻 発 時刻 着とします。
さらに街 での電車 から への乗り換えのため、電車 の発車時刻を 遅らせて、時刻 発とします。
他の電車は発車を遅らせることなく、元々乗り換え可能だった電車の間を乗り換えることができるため、 は条件を満たします。
また、条件を満たすもののうち和がこれより小さいものは存在しないため、これが答えとなります。
入力例 2Copy
10 9 100 1 10 0 1 10 2 1 100 10 3 1 100 10 4 1 100 10 5 1 100 10 6 1 100 10 7 1 100 10 8 1 100 10 9 1 100
出力例 2Copy
100 100 100 100 100 100 100 100
入力例 3Copy
4 4 10 1 2 0 1 1 2 0 10 2 3 100 200 2 4 100 200
出力例 3Copy
0 0 0
Score : points
Problem Statement
In the nation of Atcoder, there are cities numbered to , and trains numbered to . Train departs from city at time and arrives at city at time .
Given a positive integer , find a way to set non-negative integers that satisfies the following condition with the minimum possible value of .
- Condition: For all pairs satisfying , if and , then .
- In other words, for any pair of trains that are originally possible to transfer between, it is still possible to transfer even after delaying the departure and arrival times of each train by .
It can be proved that such a way to set with the minimum possible value of is unique.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print that satisfy the condition with the minimum possible sum, in that order, separated by spaces.
Sample Input 1Copy
3 6 15 1 2 10 20 1 2 20 30 2 3 25 40 2 3 35 50 3 1 15 30 3 1 45 60
Sample Output 1Copy
0 10 0 0 5
The arrival of train from city to is delayed by and becomes time .
To allow transfer from train to in city , the departure of train is delayed by , making it depart at time and arrive at time .
Further, to allow transfer from train to in city , the departure of train is delayed by , making it depart at time .
Other trains can operate without delay while still allowing transfers between originally transferable trains, so satisfies the condition.
Moreover, there is no solution with a smaller sum that satisfies the condition, so this is the answer.
Sample Input 2Copy
10 9 100 1 10 0 1 10 2 1 100 10 3 1 100 10 4 1 100 10 5 1 100 10 6 1 100 10 7 1 100 10 8 1 100 10 9 1 100
Sample Output 2Copy
100 100 100 100 100 100 100 100
Sample Input 3Copy
4 4 10 1 2 0 1 1 2 0 10 2 3 100 200 2 4 100 200
Sample Output 3Copy
0 0 0