Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は工場の生産ラインを管理しています。この工場には N 台の作業台が一列に並んでおり、左から順に 1, 2, \ldots, N の番号が付いています。各作業台 i には最初 A_i 個の部品が置かれています。
各作業台にはスイッチが付いています。作業台 i (1 \leq i \leq N - 1) のスイッチを押すと、作業台 i に置かれているすべての部品がベルトコンベアによって隣の作業台 i + 1 に移動します。移動した部品は作業台 i + 1 に既にある部品と合算され、作業台 i の部品は 0 個になります。一方、作業台 N のスイッチを押すと、作業台 N に置かれているすべての部品が生産ラインの外に排出され、作業台 N の部品は 0 個になります。排出された部品は生産ラインから完全に取り除かれ、それ以降の操作には一切関係しません。
なお、部品が 0 個の作業台のスイッチを押した場合は、何も起こりません(その作業台の部品数は 0 個のままです)。
高橋君はこれから合計 Q 回のスイッチ操作を行います。j 回目 (1 \leq j \leq Q) の操作では、作業台 B_j のスイッチを押します。操作は j = 1, 2, \ldots, Q の順に1つずつ行われ、各操作はそれ以前のすべての操作の結果を反映した状態で実行されます。なお、同じ作業台のスイッチが複数回押されることもあります。
すべての操作が終わった後、各作業台に残っている部品の個数をそれぞれ求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq Q \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq B_j \leq N (1 \leq j \leq Q)
- 入力はすべて整数
- 与えられる入力に対して、操作の途中および終了後のどの時点においても、各作業台の部品の個数は 2 \times 10^{14} を超えないことが保証される
入力
N Q A_1 A_2 \ldots A_N B_1 B_2 \vdots B_Q
- 1 行目には、作業台の数を表す整数 N と、操作の回数を表す整数 Q が、スペース区切りで与えられる。
- 2 行目には、各作業台の初期の部品の個数を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
- 3 行目から Q 行分にわたって、各操作でスイッチを押す作業台の番号が与えられる。Q = 0 の場合、この部分は存在しない。
- 2 + j 行目には、j 回目の操作で押す作業台の番号を表す整数 B_j が与えられる。
出力
すべての操作が終わった後の各作業台の部品の個数を、作業台 1 から作業台 N の順にスペース区切りで 1 行で出力せよ。
入力例 1
5 3 3 1 4 1 5 1 3 5
出力例 1
0 4 0 5 0
入力例 2
4 4 5 3 2 1 1 1 2 3
出力例 2
0 0 0 11
入力例 3
8 6 10 20 30 40 50 60 70 80 2 4 6 7 8 8
出力例 3
10 0 50 0 90 0 0 0
入力例 4
10 10 100 200 300 400 500 600 700 800 900 1000 1 2 3 4 5 6 7 8 9 10
出力例 4
0 0 0 0 0 0 0 0 0 0
入力例 5
1 1 1000000000 1
出力例 5
0
Score : 266 pts
Problem Statement
Takahashi manages the production line of a factory. The factory has N workstations arranged in a row, numbered 1, 2, \ldots, N from left to right. Initially, workstation i has A_i parts placed on it.
Each workstation has a switch. When the switch of workstation i (1 \leq i \leq N - 1) is pressed, all parts on workstation i are moved by a belt conveyor to the adjacent workstation i + 1. The moved parts are added to the parts already on workstation i + 1, and the number of parts on workstation i becomes 0. On the other hand, when the switch of workstation N is pressed, all parts on workstation N are ejected outside the production line, and the number of parts on workstation N becomes 0. Ejected parts are completely removed from the production line and have no relation to any subsequent operations.
If the switch of a workstation with 0 parts is pressed, nothing happens (the number of parts on that workstation remains 0).
Takahashi will perform a total of Q switch operations. In the j-th operation (1 \leq j \leq Q), he presses the switch of workstation B_j. The operations are performed one at a time in the order j = 1, 2, \ldots, Q, and each operation is executed in the state reflecting the results of all previous operations. Note that the switch of the same workstation may be pressed multiple times.
After all operations are completed, determine the number of parts remaining on each workstation.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq Q \leq 2 \times 10^5
- 0 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 1 \leq B_j \leq N (1 \leq j \leq Q)
- All input values are integers
- It is guaranteed that at any point during and after the operations, the number of parts on each workstation does not exceed 2 \times 10^{14}
Input
N Q A_1 A_2 \ldots A_N B_1 B_2 \vdots B_Q
- The first line contains an integer N representing the number of workstations and an integer Q representing the number of operations, separated by a space.
- The second line contains integers A_1, A_2, \ldots, A_N representing the initial number of parts on each workstation, separated by spaces.
- The following Q lines give the workstation number whose switch is pressed in each operation. If Q = 0, this part does not exist.
- The (2 + j)-th line contains an integer B_j representing the workstation number whose switch is pressed in the j-th operation.
Output
Output the number of parts on each workstation after all operations are completed, in order from workstation 1 to workstation N, separated by spaces, on a single line.
Sample Input 1
5 3 3 1 4 1 5 1 3 5
Sample Output 1
0 4 0 5 0
Sample Input 2
4 4 5 3 2 1 1 1 2 3
Sample Output 2
0 0 0 11
Sample Input 3
8 6 10 20 30 40 50 60 70 80 2 4 6 7 8 8
Sample Output 3
10 0 50 0 90 0 0 0
Sample Input 4
10 10 100 200 300 400 500 600 700 800 900 1000 1 2 3 4 5 6 7 8 9 10
Sample Output 4
0 0 0 0 0 0 0 0 0 0
Sample Input 5
1 1 1000000000 1
Sample Output 5
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は旅行の計画を立てています。
高橋君は N 台のスマートフォンを持っています。各スマートフォンには 1 から N までの番号が付けられており、スマートフォン i の現在のバッテリー残量は A_i %です。バッテリー残量は整数値で管理され、0 %未満になることはありません。
バッテリー残量が L %以下のスマートフォンは電源が切れた状態であり、使用できません。したがって、現在の時点で A_i \leq L であるスマートフォン i は最初から電源が切れています。一度電源が切れたスマートフォンは、以降再び使用可能になることはありません。
高橋君はモバイルバッテリーを 1 台持っています。現在の時刻を時刻 0 とします。時刻 0 において、高橋君はその時点で電源が入っているスマートフォンの中から K 台以下(0 台でもよい)を選んでモバイルバッテリーに接続できます。モバイルバッテリーに接続されたスマートフォンは、時刻 Y の処理がすべて終わるまで接続が維持され、その間バッテリー残量は一切減少しません。途中で接続を外したり、別のスマートフォンに付け替えたりすることはできません。また、電源が切れているスマートフォンをモバイルバッテリーに接続することはできません。
モバイルバッテリーへの接続が完了した後、時刻 1, 時刻 2, \ldots, 時刻 Y のそれぞれにおいて、以下の処理がこの順で行われます。
- バッテリー消費: 電源が入っているスマートフォンのうち、モバイルバッテリーに接続されていないもののバッテリー残量がそれぞれ 1 %減少します。
- 電源切れ判定: モバイルバッテリーに接続されていないスマートフォンについて、バッテリー残量が L %以下になったものの電源が切れます。
高橋君がモバイルバッテリーに接続するスマートフォンを最適に選んだとき、時刻 Y の処理がすべて終わった直後の時点で電源が入っている(使用可能な)スマートフォンは最大で何台になるか求めてください。モバイルバッテリーに接続されているスマートフォンも、電源が入っていればこの台数に含みます。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq L \leq 99
- 0 \leq K \leq N
- 1 \leq Y \leq 100
- 1 \leq A_i \leq 100
- 入力はすべて整数
入力
N L K Y A_1 A_2 \ldots A_N
- 1 行目には、スマートフォンの台数を表す N 、電源が切れるバッテリー残量の閾値を表す L 、モバイルバッテリーに同時に接続できる最大台数を表す K 、経過時間を表す Y が、スペース区切りで与えられる。
- 2 行目には、各スマートフォンの現在のバッテリー残量を表す A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
時刻 Y の処理がすべて終わった直後の時点で電源が入っているスマートフォンの最大台数を 1 行で出力してください。
入力例 1
5 10 2 5 50 12 8 30 14
出力例 1
4
入力例 2
8 20 3 10 100 35 25 50 18 30 22 80
出力例 2
7
入力例 3
10 0 1 50 100 48 51 30 75 50 60 10 49 55
出力例 3
6
Score : 300 pts
Problem Statement
Takahashi is planning a trip.
Takahashi has N smartphones. Each smartphone is numbered from 1 to N, and smartphone i currently has a battery level of A_i %. Battery levels are managed as integer values and never go below 0 %.
A smartphone with a battery level of L % or less is powered off and cannot be used. Therefore, smartphone i with A_i \leq L at the current time is already powered off from the start. Once a smartphone is powered off, it can never become usable again.
Takahashi has one mobile battery. Let the current time be time 0. At time 0, Takahashi can choose at most K smartphones (possibly 0) from among the currently powered-on smartphones and connect them to the mobile battery. Smartphones connected to the mobile battery remain connected until all processing at time Y is complete, and their battery levels do not decrease at all during this period. It is not possible to disconnect them midway or switch the connection to a different smartphone. Also, a powered-off smartphone cannot be connected to the mobile battery.
After the mobile battery connections are made, at each of time 1, time 2, \ldots, time Y, the following operations are performed in this order:
- Battery consumption: For each powered-on smartphone that is not connected to the mobile battery, its battery level decreases by 1 %.
- Power-off check: For smartphones not connected to the mobile battery, any smartphone whose battery level has become L % or less is powered off.
When Takahashi optimally chooses which smartphones to connect to the mobile battery, find the maximum number of smartphones that are powered on (usable) immediately after all processing at time Y is complete. Smartphones connected to the mobile battery are also counted if they are powered on.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq L \leq 99
- 0 \leq K \leq N
- 1 \leq Y \leq 100
- 1 \leq A_i \leq 100
- All inputs are integers
Input
N L K Y A_1 A_2 \ldots A_N
- The first line contains N representing the number of smartphones, L representing the battery level threshold at which a smartphone powers off, K representing the maximum number of smartphones that can be simultaneously connected to the mobile battery, and Y representing the elapsed time, separated by spaces.
- The second line contains A_1, A_2, \ldots, A_N representing the current battery levels of each smartphone, separated by spaces.
Output
Print on one line the maximum number of smartphones that are powered on immediately after all processing at time Y is complete.
Sample Input 1
5 10 2 5 50 12 8 30 14
Sample Output 1
4
Sample Input 2
8 20 3 10 100 35 25 50 18 30 22 80
Sample Output 2
7
Sample Input 3
10 0 1 50 100 48 51 30 75 50 60 10 49 55
Sample Output 3
6
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は、 N 個の商品を購入しようとしています。商品には 1 から N までの番号が付いており、商品 i の価格は W_i 円です。
高橋君は Q 枚の割引クーポンを持っています。 j 枚目のクーポンは、番号が L_j 以上 R_j 以下であるすべての商品(すなわち商品 L_j, L_j+1, \ldots, R_j)に対して、それぞれの価格を D_j 円割り引く効果があります。
同じ商品に複数のクーポンが適用される場合、割引額はすべて累積します。すなわち、商品 i に対して適用されるすべてのクーポンの割引額の合計を S_i とすると、すべてのクーポンを適用した後の商品 i の価格は \max(W_i - S_i,\ 0) 円になります。
すべてのクーポンを適用した後、価格が 0 円になった商品(すなわち W_i \leq S_i を満たす商品)の個数を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq W_i \leq 10^9
- 1 \leq L_j \leq R_j \leq N
- 1 \leq D_j \leq 10^9
- 入力はすべて整数
入力
N Q W_1 W_2 \ldots W_N L_1 R_1 D_1 L_2 R_2 D_2 \vdots L_Q R_Q D_Q
- 1 行目には、商品の個数を表す N と、クーポンの枚数を表す Q が、スペース区切りで与えられる。
- 2 行目には、各商品の初期価格を表す W_1, W_2, \ldots, W_N が、スペース区切りで与えられる。
- 3 行目から Q 行にわたって、各クーポンの情報が与えられる。
- 2 + j 行目には、 j 枚目のクーポンの対象区間の左端 L_j 、右端 R_j 、割引額 D_j が、スペース区切りで与えられる。
出力
すべてのクーポンを適用した後、価格が 0 円になった商品の個数を 1 行で出力してください。
入力例 1
5 3 100 200 150 300 50 1 3 100 2 4 150 5 5 50
出力例 1
4
入力例 2
7 4 500 300 200 400 100 600 250 1 4 200 3 5 150 2 6 100 4 7 300
出力例 2
5
入力例 3
10 6 1000000000 500 200 800 1200 300 450 100 900 600 1 5 600 3 7 250 1 3 400 6 10 400 2 8 200 5 9 500
出力例 3
8
Score : 366 pts
Problem Statement
Takahashi is about to purchase N items. The items are numbered from 1 to N, and the price of item i is W_i yen.
Takahashi has Q discount coupons. The j-th coupon has the effect of discounting the price of every item whose number is between L_j and R_j inclusive (i.e., items L_j, L_j+1, \ldots, R_j) by D_j yen each.
When multiple coupons apply to the same item, the discount amounts are all accumulated. That is, if the total discount amount from all coupons applied to item i is S_i, then the price of item i after applying all coupons becomes \max(W_i - S_i,\ 0) yen.
After applying all coupons, find the number of items whose price becomes 0 yen (i.e., items satisfying W_i \leq S_i).
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq W_i \leq 10^9
- 1 \leq L_j \leq R_j \leq N
- 1 \leq D_j \leq 10^9
- All input values are integers.
Input
N Q W_1 W_2 \ldots W_N L_1 R_1 D_1 L_2 R_2 D_2 \vdots L_Q R_Q D_Q
- The first line contains N, the number of items, and Q, the number of coupons, separated by a space.
- The second line contains the initial prices of the items W_1, W_2, \ldots, W_N, separated by spaces.
- The following Q lines contain the information for each coupon.
- The (2 + j)-th line contains the left endpoint L_j, right endpoint R_j, and discount amount D_j of the j-th coupon, separated by spaces.
Output
Print in one line the number of items whose price becomes 0 yen after applying all coupons.
Sample Input 1
5 3 100 200 150 300 50 1 3 100 2 4 150 5 5 50
Sample Output 1
4
Sample Input 2
7 4 500 300 200 400 100 600 250 1 4 200 3 5 150 2 6 100 4 7 300
Sample Output 2
5
Sample Input 3
10 6 1000000000 500 200 800 1200 300 450 100 900 600 1 5 600 3 7 250 1 3 400 6 10 400 2 8 200 5 9 500
Sample Output 3
8
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は 1 本の長いロープを持っています。
このロープは N 個の区間に分かれており、各区間には左から順に 1 から N までの番号が付けられています。区間 i(1 \leq i \leq N)の長さは A_i であり、ロープ全体の長さは A_1 + A_2 + \cdots + A_N です。
高橋君はこのロープをちょうど K 本に分割したいと考えています。ロープを切ることができるのは、区間 i と区間 i+1 の間の境目(1 \leq i \leq N-1)に限られます。ちょうど K 本に分割するには、N - 1 箇所ある境目のうちちょうど K - 1 箇所を選んで切ります。区間を取り除くことはできず、すべての区間はいずれかのロープに属さなければなりません。
この結果、分割後の各ロープは、番号が連続する 1 つ以上の区間から構成されます。各ロープの長さは、そのロープに含まれる区間の長さの合計です。
高橋君は、分割後の K 本のロープのうち最も長いものの長さをできるだけ短くしたいと思っています。
最適な切り方をしたとき、K 本のロープのうち最も長いものの長さの最小値を求めてください。
制約
- 1 \leq K \leq N \leq 10^5
- 1 \leq A_i \leq 10^9
- 入力はすべて整数
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、区間の数を表す整数 N と、分割後のロープの本数を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、N 個の区間それぞれの長さを表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
最適な切り方をしたとき、分割後の K 本のロープのうち最も長いものの長さの最小値を 1 行で出力せよ。
入力例 1
5 3 1 2 3 4 5
出力例 1
6
入力例 2
8 4 3 1 4 1 5 9 2 6
出力例 2
9
入力例 3
10 3 100 200 300 400 500 600 700 800 900 1000
出力例 3
2100
Score : 400 pts
Problem Statement
Takahashi has one long rope.
This rope is divided into N sections, and each section is numbered from 1 to N from left to right. The length of section i (1 \leq i \leq N) is A_i, and the total length of the rope is A_1 + A_2 + \cdots + A_N.
Takahashi wants to divide this rope into exactly K pieces. The rope can only be cut at the boundary between section i and section i+1 (1 \leq i \leq N-1). To divide the rope into exactly K pieces, he selects exactly K - 1 of the N - 1 available boundaries and cuts at those positions. Sections cannot be removed, and every section must belong to exactly one of the resulting pieces.
As a result, each piece after the division consists of one or more consecutively numbered sections. The length of each piece is the sum of the lengths of the sections it contains.
Takahashi wants to minimize the length of the longest piece among the K pieces after the division.
Find the minimum possible length of the longest piece among the K pieces when the cuts are made optimally.
Constraints
- 1 \leq K \leq N \leq 10^5
- 1 \leq A_i \leq 10^9
- All inputs are integers.
Input
N K A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of sections and an integer K representing the number of pieces after division, separated by a space.
- The second line contains N integers A_1, A_2, \ldots, A_N representing the lengths of the N sections, separated by spaces.
Output
Print in one line the minimum possible length of the longest piece among the K pieces when the cuts are made optimally.
Sample Input 1
5 3 1 2 3 4 5
Sample Output 1
6
Sample Input 2
8 4 3 1 4 1 5 9 2 6
Sample Output 2
9
Sample Input 3
10 3 100 200 300 400 500 600 700 800 900 1000
Sample Output 3
2100
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
高橋君は旅行プランナーです。ある観光エリアには N 個の観光スポットがあり、それぞれ 1 から N までの番号が付けられています。これらのスポット同士を結ぶ双方向の道路が M 本あります。
各観光スポット i には満足度 c_i が設定されています。高橋君は、観光スポット S を出発してスポット T に到着する観光ルートを提案したいと考えています。
ここで、観光ルートとは、S から T への単純パス、すなわちスポットの列 S = v_0, v_1, \ldots, v_k = T(k \geq 1)であって、以下の条件を全て満たすものです。
- 列に含まれるスポットは全て異なる(同じスポットを 2 回以上訪れない)。
- 連続する 2 つのスポット v_{i-1} と v_i(1 \leq i \leq k)の間に道路が存在する。
観光ルートのスコアを、そのルート上で訪れる全てのスポット(始点 S と終点 T を含む)の満足度の総和 \displaystyle\sum_{i=0}^{k} c_{v_i} と定義します。
S から T への全ての観光ルートについてスコアを計算したとき、その平均値(スコアの総和を観光ルートの総数で割った値)を求めてください。
なお、S から T への観光ルートが少なくとも 1 つ存在することが保証されます。
制約
- 2 \leq N \leq 18
- 1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq S \leq N
- 1 \leq T \leq N
- S \neq T
- 1 \leq c_i \leq 1000(1 \leq i \leq N)
- 1 \leq u_j < v_j \leq N(1 \leq j \leq M)
- 同じスポットの組を結ぶ道路は高々 1 本である(多重辺はない)
- 自己ループはない
- S から T への単純パスが少なくとも 1 つ存在する
- 入力は全て整数である
入力
入力は以下の形式で与えられます。
N M S T c_1 c_2 \vdots c_N u_1 v_1 u_2 v_2 \vdots u_M v_M
1 行目に、観光スポットの数 N、道路の数 M、出発スポットの番号 S、到着スポットの番号 T がスペース区切りで与えられます。
続く N 行のうち i 行目(1 \leq i \leq N)に、スポット i の満足度 c_i が与えられます。
続く M 行のうち j 行目(1 \leq j \leq M)に、2 つの整数 u_j, v_j がスペース区切りで与えられ、スポット u_j とスポット v_j が双方向の道路で結ばれていることを表します。各道路について u_j < v_j を満たします。
出力
S から T への全ての観光ルートにおけるスコアの平均値を小数で 1 行に出力してください。真の値との絶対誤差または相対誤差が 10^{-6} 以下であれば正解とみなされます。
入力例 1
3 2 1 3 10 20 30 1 2 2 3
出力例 1
60.000000000000000
入力例 2
4 4 1 4 5 8 6 7 1 2 2 4 1 3 3 4
出力例 2
19.000000000000000
入力例 3
6 8 1 6 4 9 7 3 8 10 1 2 1 3 2 4 3 4 2 5 4 5 4 6 5 6
出力例 3
31.714285714285715
入力例 4
10 16 1 10 12 7 15 9 20 5 11 14 8 13 1 2 1 3 1 4 2 5 2 6 3 5 3 7 4 6 4 7 5 6 5 8 6 8 6 9 7 8 7 9 8 10
出力例 4
87.619047619047620
入力例 5
2 1 1 2 1 1000 1 2
出力例 5
1001.000000000000000
Score : 466 pts
Problem Statement
Takahashi is a travel planner. A certain sightseeing area has N tourist spots, numbered from 1 to N. There are M bidirectional roads connecting these spots.
Each tourist spot i has a satisfaction value c_i. Takahashi wants to propose a sightseeing route that starts at spot S and arrives at spot T.
Here, a sightseeing route is a simple path from S to T, that is, a sequence of spots S = v_0, v_1, \ldots, v_k = T (k \geq 1) satisfying all of the following conditions:
- All spots in the sequence are distinct (no spot is visited more than once).
- For each pair of consecutive spots v_{i-1} and v_i (1 \leq i \leq k), a road exists between them.
The score of a sightseeing route is defined as the sum of satisfaction values of all spots visited along the route (including the starting spot S and the ending spot T): \displaystyle\sum_{i=0}^{k} c_{v_i}.
Compute the average score over all sightseeing routes from S to T (i.e., the sum of scores of all routes divided by the total number of routes).
It is guaranteed that at least one sightseeing route from S to T exists.
Constraints
- 2 \leq N \leq 18
- 1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq S \leq N
- 1 \leq T \leq N
- S \neq T
- 1 \leq c_i \leq 1000 (1 \leq i \leq N)
- 1 \leq u_j < v_j \leq N (1 \leq j \leq M)
- There is at most one road between any pair of spots (no multi-edges)
- There are no self-loops
- At least one simple path from S to T exists
- All input values are integers
Input
The input is given in the following format:
N M S T c_1 c_2 \vdots c_N u_1 v_1 u_2 v_2 \vdots u_M v_M
The first line contains the number of tourist spots N, the number of roads M, the starting spot number S, and the destination spot number T, separated by spaces.
In the following N lines, the i-th line (1 \leq i \leq N) contains the satisfaction value c_i of spot i.
In the following M lines, the j-th line (1 \leq j \leq M) contains two integers u_j and v_j separated by a space, indicating that spots u_j and v_j are connected by a bidirectional road. Each road satisfies u_j < v_j.
Output
Output in a single line the average score over all sightseeing routes from S to T as a decimal number. The answer will be considered correct if the absolute or relative error from the true value is at most 10^{-6}.
Sample Input 1
3 2 1 3 10 20 30 1 2 2 3
Sample Output 1
60.000000000000000
Sample Input 2
4 4 1 4 5 8 6 7 1 2 2 4 1 3 3 4
Sample Output 2
19.000000000000000
Sample Input 3
6 8 1 6 4 9 7 3 8 10 1 2 1 3 2 4 3 4 2 5 4 5 4 6 5 6
Sample Output 3
31.714285714285715
Sample Input 4
10 16 1 10 12 7 15 9 20 5 11 14 8 13 1 2 1 3 1 4 2 5 2 6 3 5 3 7 4 6 4 7 5 6 5 8 6 8 6 9 7 8 7 9 8 10
Sample Output 4
87.619047619047620
Sample Input 5
2 1 1 2 1 1000 1 2
Sample Output 5
1001.000000000000000