CF2253F.4-beauty

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For a set of integers SS, define its divisibility characteristic as the number of ordered pairs (x,y)(x, y) such that x≠yx \ne y, xx and yy belong to SS, and xx is divisible by yy.

For a set of integers AA, define its 44-beauty as follows:

  • consider all sets of four distinct numbers that belong to AA and form an arithmetic progression;
  • find the maximum divisibility characteristic among all such sets.

If there are no suitable sets of four numbers, then the 44-beauty equals 00.

Initially, the set 1,2,…,n{1, 2, \ldots, n} is given. You may remove numbers from it. Removing the number ii costs mim_i coins.

Calculate the minimum number of coins you have to spend in order to decrease the 44-beauty of the set.

对于整数集合 SS,定义其整除特征值为满足以下条件的有序对 (x,y)(x, y) 的个数:x≠yx \ne y,且 x,y∈Sx, y \in S,且 xx 被 yy 整除。

对于整数集合 AA,定义其4-美值如下:

  • 考虑所有由 AA 中四个互不相同的数组成的等差数列;
  • 在所有这些四元组中,找出最大的整除特征值。

若不存在满足条件的四元组,则该集合的 4-美值定义为 00。

初始时给定集合 {1,2,…,n}\{1, 2, \ldots, n\}。你可以从中删除若干数字。删除数字 ii 的代价为 mim_i 枚金币。

请计算为使该集合的 4-美值降低所需花费的最少金币数。

输入格式

The first line contains one integer nn (4≤n≤5⋅1054 \le n \le 5 \cdot 10^5) — the number of elements in the initial set.

The second line contains nn integers m1,m2,…,mnm_1, m_2, \ldots, m_n (1≤mi≤1091 \le m_i \le 10^9), where mim_i is the cost of removing the number ii.

第一行包含一个整数 nn(4≤n≤5⋅1054 \le n \le 5 \cdot 10^5)—— 初始集合中元素的个数。

第二行包含 nn 个整数 m1,m2,…,mnm_1, m_2, \ldots, m_n(1≤mi≤1091 \le m_i \le 10^9),其中 mim_i 表示移除数字 ii 的代价。

输出格式

Print one integer — the minimum number of coins you have to spend in order to decrease the 44-beauty of the set. It can be shown that it is always possible.

输出一个整数——为使该集合的 44-beauty 减小所需花费的最少硬币数。可以证明,这总是可行的。

输入输出样例

  • 输入#1

    4
    5 3 7 2

    输出#1

    2
  • 输入#2

    5
    1 100 100 100 1

    输出#2

    1
  • 输入#3

    8
    2 10 100 10 100 3 100 100

    输出#3

    5
  • 输入#4

    10
    9 9 7 4 8 2 6 5 1 10

    输出#4

    4

说明/提示

In the first example, the only arithmetic progression of four numbers is 1,2,3,41, 2, 3, 4. Its divisibility characteristic equals 44. It is sufficient to remove the number 44, paying 22 coins.

In the second example, it is sufficient to remove the number 11.

In the third example, it is optimal to remove the numbers 11 and 66, paying 2+3=52+3=5 coins.

在第一个例子中,唯一的四项等差数列是 1,2,3,41, 2, 3, 4。其整除特征值为 44。只需移除数字 44,花费 22 枚硬币。

在第二个例子中,只需移除数字 11。

在第三个例子中,最优策略是移除数字 11 和 66,花费 2+3=52+3=5 枚硬币。

输入解题思路,AI测评打分。不知道怎么写?

首页