2017年ACM第八届山东省赛J题:company

Posted 0一叶0知秋0

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017年ACM第八届山东省赛J题:company相关的知识,希望对你有一定的参考价值。

J题:company

题目描述

There are n kinds of goods in the company, with each of them has a inventory of cnti and direct unit benefit vali. Now you find due to price changes, for any goods sold on day i, if its direct benefit is val, the total benefit would be i?val.
Beginning from the first day, you can and must sell only one good per day until you can‘t or don‘t want to do so. If you are allowed to leave some goods unsold, what‘s the max total benefit you can get in the end?

输入

The first line contains an integers n(1≤n≤1000).
The second line contains n integers val1,val2,..,valn(?100≤vali.≤100).
The third line contains n integers cnt1,cnt2,..,cntn(1≤cnti≤100).

输出

Output an integer in a single line, indicating the max total benefit.

Hint: sell goods whose price with order as -1, 5, 6, 6, the total benefit would be -1*1 + 5*2 + 6*3 + 6*4 = 51.

样例输入

4
-1 -100 5 6
1 1 1 2

样例输出

51

题意:商店买东西,有n种商品,每种商品卖出去以后得到的价值是v,每种商品有c件,第i天卖出v价值的商品,得到的价值是i*v,时间是从第一天开始,每天只能卖一件,对于每件商品你可以选择卖或者不卖;

思路:把商品价值从小到大排列  然后从后向前扫 sum 记录已经扫过的商品的总价值(val)  ans 记录已经卖出的 商品价值(i*val),

 

#include <cstdio>
#include <iostream> 
#include <algorithm>

using namespace std ; 


#define maxn 1050 
#define LL long long 

struct node {
    int val ; 
    int cnt ; 
};
node num[maxn] ; 

bool cmp(node a , node b ){
    return a.val < b.val ; 
}

int main(){
    int n ; 
    LL ans , sum ; 
    
    while(~scanf("%d" , &n)){
        sum = ans = 0 ; 
        for(int i=0 ; i<n ; i++){
            scanf("%d" , &num[i].val) ; 
        }
        for(int i=0 ; i<n ; i++){
            scanf("%d" , &num[i].cnt) ; 
        }
        
        sort(num , num +n , cmp) ; 
        
        for(int i=n-1 ; i>=0 ; i--){
            for(int j=0 ; j<num[i].cnt ; j++){
                if(ans + sum + num[i].val >=ans){
                    ans = ans + sum + num[i].val ; 
                    sum = sum + num[i].val ;  
                }
            }
        }
        printf("%lld\n" , ans) ; //注意 ans 必须开 LL 
    }    
    return 0 ; 
}

 

以上是关于2017年ACM第八届山东省赛J题:company的主要内容,如果未能解决你的问题,请参考以下文章

2017年ACM第八届山东省赛F题:quadratic equation(离散数学蕴含式)

2017年ACM第八届山东省赛G题:sum of power

2017年ACM第八届山东省赛I题: Parity check(判断 第n项斐波那契数列奇偶性)

山东省第八届ACM省赛游记

第八届山东省ACM大学生程序设计竞赛个人总结

第八届山东ACM省赛F题-quadratic equation