zoukankan      html  css  js  c++  java
  • CF DIV 2 206 C. Vasya and Robot

    C. Vasya and Robot
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.

    Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:

    1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
    2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;

    Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.

    Input

    The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).

    The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).

    Output

    In the single line print a single number — the answer to the problem.

    Sample test(s)
    input
    3 4 4 19 1
    42 3 99
    output
    576
    input
    4 7 2 3 9
    1 2 3 4
    output
    34
    Note

    Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.

    The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.

     枚举n个物品里面有多少个是用左手拿的。。。。

    /*
     * Author:  
     * Created Time:  2013/10/14 15:09:49
     * File Name: A.cpp
     * solve: A.cpp
     */
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<stack>
    #include<set>
    #include<iostream>
    #include<vector>
    #include<queue>
    //ios_base::sync_with_stdio(false);
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    #define sz(v) ((int)(v).size())
    #define rep(i, a, b) for (int i = (a); i < (b); ++i)
    #define repf(i, a, b) for (int i = (a); i <= (b); ++i)
    #define repd(i, a, b) for (int i = (a); i >= (b); --i)
    #define clr(x) memset(x,0,sizeof(x))
    #define clrs( x , y ) memset(x,y,sizeof(x))
    #define out(x) printf(#x" %d
    ", x)
    #define sqr(x) ((x) * (x))
    typedef long long LL;
    
    const LL INF = 10000000000000;
    const double eps = 1e-8;
    const int maxn = 100100;
    
    int sgn(const double &x) {  return (x > eps) - (x < -eps); }
    LL sum[maxn];
    LL w[maxn];
    LL n,l,r,ql,qr;
    LL cal(LL num)
    {
        LL L = num;
        LL R = n - L;
        LL ans = 0;
        ans += l*sum[L];
        ans += r*(sum[n] - sum[L]);
        if(R > L)
        {
            ans += (R - L - 1)*qr;
        }else if(R < L)
            ans += (L - R - 1)*ql;
        return ans;
    }
    int main() 
    {
        //freopen("in.txt","r",stdin);
        scanf("%I64d%I64d%I64d%I64d%I64d",&n,&l,&r,&ql,&qr);
        
        sum[0] = 0;
        repf(i,1,n)
        {
            scanf("%I64d",&w[i]);
            sum[i] = sum[i-1] + w[i];
        }
        
        LL ans = INF;
        repf(i,0,n)
            ans = min(ans,cal(i));
        cout<<ans<<endl;
        
        return 0;
    }
  • 相关阅读:
    个人浏览器安装的插件
    angularjs 1 Failed to read the 'selectionStart' property from 'HTMLInputElement':
    git 配置用户名和邮箱
    修改Atom 隐藏.gitignore忽略的文件/文件夹的配置
    Ubuntu 安装php_intl 扩展
    yii2 ./yii command : No such file or directory
    vagrant yii2 Exception 'yiidbException' with message 'SQLSTATE[HY000] [2002]
    [转载]Ubuntu 14.04设置固定ip
    [转载]删除所有的.svn文件夹
    Centos7.2正常启动关闭CDH5.16.1
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3369259.html
Copyright © 2011-2022 走看看