山东省第八届 ACM 省赛 company (贪心、水)

网友投稿 596 2022-08-26

山东省第八届 ACM 省赛 company (贪心、水)

山东省第八届 ACM 省赛 company (贪心、水)

Problem 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.

Example Input

4-1 -100 5 61 1 1 2

Example Output

51

题意

有 ​​n​​​ 种商品以及这些商品的价值与数量,每天只能购买一件商品,且 ​​ans​​​ 为 sum(ti×vali) ,其中 ti 为第几天,求最终所能得到的最大 ​​ans​​ 。

思路

我们可以先把所有商品的价值存在数组中(包括数量大于一的),排序并顺便求出当前的 ​​ans​​ 。

然后从数组最左边开始枚举,判断是否需要去除当前商品,若去除,则 ​​ans-=a[i]-sum[top-1]+sum[i]​​ ,因为总天数减少了一天,所以后面的所有商品价值和也应该减少。

判断如果当前得到新的 ​​ans​​​ 变小了,跳出,输出最大的 ​​ans​​ 。

AC 代码

#include#include#include#include#include#includeusing namespace std;#include#include#define eps (1e-8)typedef long long LL;const int mod = 1e9+7;const int maxn = 100000;int a[maxn],sum[maxn],d[maxn];int main(){ int n; while(~scanf("%d",&n)) { int top=n; for(int i=0; ians) ans=s; else break; } cout<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:山东省第八届 ACM 省赛 CF (01背包、水)
下一篇:Swift初始化的安全方式(swift运行机制)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~