company 贪心

 

company

Time Limit: 1000 msMemory Limit: 65536 KiB
 

Problem Description

There are n kinds of goods in the company, with each of them has a inventory of  and direct unit benefit . 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 ival.
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?

Input

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

Output

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

Sample Input

4
-1 -100 5 6
1 1 1 2

Sample Output

51

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.

Source

“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

 

题意:有n种商品,每种商品有多种,每种商品的价值是v,每种商品有c件,第day天只能卖一件商品,最后价值为 day*v

最后要求其最大价值

思路:我们把每种商品都购买,价值越大的商品,在天数越大时购买,其价值就会越大(day*v[i]),而且有的商品有多件,这就要把商品都放开,件数多的商品也都 一 一 放在d数组中,这样利于判断,然后将d数组从小到大排序,寻找第一个价值为>0的货物,从它为第一天开始卖会出来一个总的价值,然后从它的前一天开始卖会出来一个总的价值,然后依次往前推移,在过程中就可以把最大价值寻找出来(用  if判断语句)

-100-1566value
  12335
 123451
12345-33(赔钱了)

 

注:每一件商品都要卖,只不过我们要找的是卖货物的最大价值

 

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
#define maxn 100010
#define INF 0x3f3f3f3f
int d[maxn];
int v[2000];
int c[2000];
long long int sum,ma; //sum和ma必须要定义成long long 不然就会Runtime Error 将类型换为long long之后 就Accepted
 int main(){
	int n,i,j,k;
	scanf("%d",&n);
    for(i=0; i<n; i++)
	{
    	scanf("%d",&v[i]);
	}	
	for(i=0; i<n; i++)
	{
		scanf("%d",&c[i]);
	}
	int x=1;
	for(i=0;i<n;i++){
		for(j=0;j<c[i];j++){
			d[x++]=v[i];
		}
	}
	sort(d+1,d+x);
	d[0]=-1;//将d数组的前后位置设置好,放止这个数组里的数据全部都是负数
	d[x]=1;
	for(i=1;i<x;i++){
		if(d[i]>=0 && d[i-1]<0){
			k=i;
			break;
		}
	}
	  ma=-INF;
	for(i=0;i<k;i++){
		int day=1;
		sum=0;
		for(j=k-i;j<x;j++){
			sum+=day*d[j];
			day++;
		}
		if(ma<sum)//找出最大价值
		ma=sum;
	}
	printf("%lld\n",ma);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值