zoukankan      html  css  js  c++  java
  • 10.16T2 平方差

    Description

    冈伦确定了 个时间节点,每一个节点都存在影响世界线的“因素”。只不过,时间跳跃会对冈伦带来不可逆的影响,他们经过试验,将该影响数字化:
    我们假定时间是一条数轴,现在的时间是原点 ,我们把所有的“因素”存在的时间点也用数轴上的数字表示,时间点越是往前,对应的值便越大,数轴上长为 的时间段称作 时间单位。
    当冈伦到达“因素”存在的时间点时,可以每次都用一定的代价X将之收集在容器中,而当冈伦回到现在所在的时间点时,也可以用相等的代价X将之放入特殊的分析装置中(每次放入容器的“因素”无论多少都只花费一份代价 X)。
    通过进一步的试验,他们发现:与收集“因素”的容器一起进行时间跳跃会给身体带来更大的负担,对于每1时间单位的时间跳跃,冈伦的负担为 
    (当 前 容 器 中 因 素 个 数+1)^2 。
    现在,你需要求得一种收集方式,使完成收集对冈伦带的影响最小。

    Input

    第一行两个整数 n,X ,表示“因素”的个数与代价 X。
    第二行n个正整数di,表示第i远的“因素”距现在时间点的距离,不会有两个在相同时间点的因素。

    Output

    输出一行一个整数,表示冈伦会受到的最小影响。

    Sample Input

    2 50 1 10

    Sample Output

    205 先以10点代价走到时间点10 ; 以50点代价收集位于该时间点的“因素”; 再以36 点代价走到时间点1 ; 以50点代价收集位于该时间点的“因素”; 最后以9点代价走回现在,并以50 点代价把“因素”放置在分析器中。

    Hint

    数据范围及约定
    40%数据,n<=5;
    60%数据,n<=2000;X<=2*10^4;di<=4*10^4;
    100%数据,n<=2*10^5;X<=10^9;di<=10^9;
     
     
     
     
    code:
     1 #include<iostream>
     2 #include<cstdio>
     3 #define N 200006
     4 using namespace std;
     5 long long a[N];
     6 int main(){
     7     long long n,X;
     8     cin>>n>>X;
     9     for(long long i=1;i<=n;i++){
    10         cin>>a[i];
    11         a[i]+=a[i-1];
    12     }
    13     long long ans=1e18;
    14     for(long long k=1;k<=n;k++){
    15         long long num=3ll,sum=0;
    16         for(long long i=n;i>=1;i-=k){
    17             sum+=(a[i]-a[max(0ll,i-k)])*(max(num,5ll));
    18             num+=2;
    19             if(sum>=ans)break;
    20         }
    21         ans=min(ans,sum+(long long)(k+n)*X);
    22     }
    23     cout<<ans;
    24     return 0;
    25 }

    over

  • 相关阅读:
    ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending
    如何从vss中分离程序
    String or binary data would be truncated
    the pop3 service failed to retrieve authentication type and cannot continue
    The POP3 service failed to start because
    IIS Error he system cannot find the file specified _找不到页面
    pku2575Jolly Jumpers
    pku2940Wine Trading in Gergovia
    pku3219二项式系数
    pku1029false coin
  • 原文地址:https://www.cnblogs.com/saionjisekai/p/9798917.html
Copyright © 2011-2022 走看看