B. Power Sequence

https://codeforces.com/contest/1397/problem/B

Let's call a list of positive integers a0,a1,...,an−1a0,a1,...,an−1 a power sequence if there is a positive integer cc, so that for every 0≤i≤n−10≤i≤n−1 then ai=ciai=ci.

Given a list of nn positive integers a0,a1,...,an−1a0,a1,...,an−1, you are allowed to:

  • Reorder the list (i.e. pick a permutation pp of {0,1,...,n−1}{0,1,...,n−1} and change aiai to apiapi), then
  • Do the following operation any number of times: pick an index ii and change aiai to ai−1ai−1 or ai+1ai+1 (i.e. increment or decrement aiai by 11) with a cost of 11.

Find the minimum cost to transform a0,a1,...,an−1a0,a1,...,an−1 into a power sequence.

Input

The first line contains an integer nn (3≤n≤1053≤n≤105).

The second line contains nn integers a0,a1,...,an−1a0,a1,...,an−1 (1≤ai≤1091≤ai≤109).

Output

Print the minimum cost to transform a0,a1,...,an−1a0,a1,...,an−1 into a power sequence.

Examples

input

Copy

3
1 3 2

output

Copy

1

input

Copy

3
1000000000 1000000000 1000000000

output

Copy

1999982505

Note

In the first example, we first reorder {1,3,2}{1,3,2} into {1,2,3}{1,2,3}, then increment a2a2 to 44 with cost 11 to get a power sequence {1,2,4}{1,2,4}.


思路:直觉上这题的费用状态是类似一个开口向上的二次函数,感觉是个三分的类型。然后发现这题最多的花费上限的c=1的时候, ans(max)=∑(a[i]−1).因为c范围在1-无穷,根据函数图像随着c变得很大后面的ans肯定大于c=1的函数值。

所以直接枚举c,当出现大于c=1的函数值的时候break;

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
const LL inf=1e18;
LL a[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  for(LL i=0;i<n;i++) cin>>a[i];
  sort(a,a+n); 
  LL ans=inf;
  for(LL c=1;c<=1000000; c++)
  {
  	 LL cur=1;
  	 LL now=0;
  	 bool flag=1;
  	 for(LL i=0;i<n;i++)
  	 {
  	 	if(cur>=1000000000000){flag=0;break;}
  		now+=fabs(a[i]-cur);
		cur*=c;	 	
	 }
	 if(flag) ans=min(ans,now);
  }
  cout<<ans<<endl;
return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
翻译Agent 𝑐 𝑖 . In this paper, we regard each charging station 𝑐 𝑖 ∈ 𝐶 as an individual agent. Each agent will make timely recommendation decisions for a sequence of charging requests 𝑄 that keep coming throughout a day with multiple long-term optimization goals. Observation 𝑜 𝑖 𝑡 . Given a charging request 𝑞𝑡 , we define the observation 𝑜 𝑖 𝑡 of agent 𝑐 𝑖 as a combination of the index of 𝑐 𝑖 , the real-world time 𝑇𝑡 , the number of current avail able charging spots of 𝑐 𝑖 (supply), the number of charging requests around 𝑐 𝑖 in the near future (future demand), the charging power of 𝑐 𝑖 , the estimated time of arrival (ETA) from location 𝑙𝑡 to 𝑐 𝑖 , and the CP of 𝑐 𝑖 at the next ETA. We further define 𝑠𝑡 = {𝑜 1 𝑡 , 𝑜2 𝑡 , . . . , 𝑜𝑁 𝑡 } as the state of all agents at step 𝑡. Action 𝑎 𝑖 𝑡 . Given an observation 𝑜 𝑖 𝑡 , an intuitional design for the action of agent𝑐 𝑖 is a binary decision, i.e., recommending 𝑞𝑡 to itself for charging or not. However, because one 𝑞𝑡 can only choose one station for charging, multiple agents’ actions may be tied together and are difficult to coordinate. Inspired by the bidding mechanism, we design each agent 𝑐 𝑖 offers a scalar value to "bid" for 𝑞𝑡 as its action 𝑎 𝑖 𝑡 . By defining 𝑢𝑡 = {𝑎 1 𝑡 , 𝑎2 𝑡 , . . . , 𝑎𝑁 𝑡 } as the joint action, 𝑞𝑡 will be recommended to the agent with the highest "bid" value, i.e., 𝑟𝑐𝑡 = 𝑐 𝑖 , where 𝑖 = arg max(𝑢𝑡)
07-11

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值