Codeforces Round 445 (Div. 1, based on Technocup 2018 Elimination Round 3)
翻译中…
You are given a sequence of integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$. Let
, and
for $1 ≤ *i* < *n*$. Here,
denotes the modulus operation. Find the maximum value of $*f*(*x*, 1)$ over all nonnegative integers $*x*$.
翻译中…
Input
翻译中…
The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 200000$) — the length of the sequence.
翻译中…
The second lines contains $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 10^{13}$) — the elements of the sequence.
翻译中…
Output
翻译中…
Output a single integer — the maximum value of $*f*(*x*, 1)$ over all nonnegative integers $*x*$.
翻译中…
Note
翻译中…
In the first example you can choose, for example, $*x* = 19$.
翻译中…
In the second example you can choose, for example, $*x* = 3$ or $*x* = 2$.
翻译中…
样例
Input #1
2
10 5
Output #1
13
InputCopy
OutputCopy
Input #2
5
5 4 3 2 1
Output #2
6
InputCopy
OutputCopy
Input #3
4
5 10 5 10
Output #3
16
InputCopy
OutputCopy
题目信息
题号
889E
时间限制
2 s
内存限制
256 MB
标签
二分
动态规划
数学
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。