探索flutter框架开发的app在移动应用市场的潜力与挑战
632
2022-08-26
山东省第八届 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
发表评论
暂时没有评论,来抢沙发吧~