zcmu-2010


2010: company Time Limit: 1 Sec   Memory Limit: 256 MB
Submit: 74   Solved: 14
[ Submit][ Status][ Web Board]

Description

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?

Input

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

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.

Sample Input

4-1 -100 5 61 1 1 2

Sample Output

51

题意:给你n个物品,每个有v价值(有可能为负),c的库存,物品在第i天卖出有i*v的价值,求卖出的价值最大

注意:这里买的天数不是n天对于一件物品可以卖出也立业不卖出。

解析:每件物品价值排序,算出每天物品的价值,和s[i]天的价值总和,再从左枚举,删除物品,则ans-=b[i]

-s[cnt-1]+s[i].因为删除一件物品总的天数要减一。

代码:

#include<bits/stdc++.h>
using namespace std;

const int N=100000+5;
typedef long long LL;
struct node
{
	int v,c;
}a[N];
int s[N],b[N];

int main()
{
	int n,cnt;
	scanf("%d",&n);
	for(int i=0; i<n; i++)scanf("%d",&a[i].v);
	cnt=0;
	for(int i=0; i<n; i++)
	{
		scanf("%d",&a[i].c);
		for(int j=0; j<a[i].c; j++)
		{
			b[cnt++]=a[i].v;
		}
	}
	
	sort(b,b+cnt);
	s[0]=b[0];
	LL ans=b[0];//long long 注意点。
	
	for(int i=1; i<cnt; i++)
	{
		s[i]=s[i-1]+b[i];
		ans+=(i+1)*b[i];
	}
	
	for(int i=0; i<cnt; i++)
	{
		LL ss=ans-b[i]-s[cnt-1]+s[i];
		if(ss>ans)ans=ss;
		else break;
	}
	printf("%lld\n",ans);
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值