logo AlgoBeat OnlineJudge
登录 注册

#216433. [IATI 2026] Arithmetic Progression

内存限制:1024 MiB 时间限制:5000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Sashka has a sequence of positive integers, a positive integer , and an arithmetic progression (A sequence is an arithmetic progression if and only if for all for some constant .), defined by its first element and the difference between its consecutive elements , which are both positive integers.

She is interested in the subsequences (A subsequence of a sequence is obtained by removing zero or more elements from it, without changing the order of the remaining elements.) of length of denoted as .

Write a program that calculates the minimal sum of respective multiplications of such a subsequence with the first entries of the arithmetic progression, meaning the following sum is minimized:

Implementation details

You should implement the function :

 __int128 solve(std::vector <long long> A, int K, long long S, int D)
  • : vector, containing
  • : the length of the subsequence
  • : the first entry of the arithmetic progression
  • : the difference of the arithmetic progression

Your function should return the minimal possible sum of the described type. As it may be too large, your function should return the variable of the non-standard type for bit integers. The header file contains overloaded definitions for the and operators, allowing the use of , and for variables.

输入格式

Input format:

  • line 1: ;
  • line 2: .

输出格式

Output format:

  • line 1: one integer, equal to the answer returned by \verb|solve|

样例

样例输入 1

3 2 1 1
5 1 4

样例输出 1

7

样例输入 2

3 2 6 1
5 1 4

样例输出 2

34

样例输入 3

6 4 4 6
18 12 8 14 19 11

样例输出 3

562

数据范围与提示

Comment 1

The arithmetic progression is . We choose , and we get the optimal result:

Comment 2

The arithmetic progression is . We choose , and we get the optimal result:

Comment 3

The arithmetic progression is . We choose , and we get the optimal result:

Constraints

Subtasks

Subtask Points Required subtasks Other constraints
The sample tests.
is obtained by uniformly shuffling a sequence that is chosen by the author for the given test.

The points for a given subtask are obtained only if all the tests for it and the required subtasks are successfully passed.