山东省第八届 ACM 省赛 company (贪心、水)
来源:互联网 发布:淘宝卖家积分等级:皇冠 编辑:程序博客网 时间:2024/05/22 10:44
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
为 ans
。
思路
我们可以先把所有商品的价值存在数组中(包括数量大于一的),排序并顺便求出当前的 ans
。
然后从数组最左边开始枚举,判断是否需要去除当前商品,若去除,则 ans-=a[i]-sum[top-1]+sum[i]
,因为总天数减少了一天,所以后面的所有商品价值和也应该减少。
判断如果当前得到新的 ans
变小了,跳出,输出最大的 ans
。
AC 代码
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>using namespace std;#include<queue>#include<map>#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; i<n; i++) scanf("%d",a+i); for(int i=0; i<n; i++) { scanf("%d",d+i); for(int j=1; j<d[i]; j++) a[top++]=a[i]; } sort(a,a+top); sum[0]=a[0]; LL ans=a[0]; for(int i=1; i<top; i++) { sum[i]=sum[i-1]+a[i]; ans+=(i+1)*a[i]; } for(int i=0; i<top; i++) { LL s=ans-a[i]-sum[top-1]+sum[i]; if(s>ans) ans=s; else break; } cout<<ans<<endl; } return 0;}
- 山东省第八届 ACM 省赛 company (贪心、水)
- 山东省第八届ACM省赛J题company(C-DP,贪心)
- 山东省第八届acm省赛 company
- 第八届山东省赛题 J company (贪心,水)
- 山东省第八届ACM省赛 J 题(company)
- 第八届ACM山东省赛 J company
- 山东省第八届ACM省赛 J 题 company(两种思路) 解答
- 贪心算法之子段和,山东省第八届acm大赛J题company,SDUT3902
- ACM 第八届山东省赛 J company SDUT 3902
- 山东省第八届acm省赛K题 贪心+dp
- 山东省第八届 ACM 省赛 quadratic equation (水、坑)
- 山东省第八届 ACM 省赛 CF (01背包、水)
- 山东省第八届 ACM 省赛 Parity check (规律、水)
- 山东省第八届ACM省赛 I 题(Parity check)
- 山东省第八届ACM省赛 F 题(quadratic equation)
- 山东省第八届ACM省赛 K 题(CF)
- 山东省第八届 ACM 省赛 Quadrat (找规律)
- 山东省第八届ACM省赛 Quadrat(打表找规律)
- centos7.3 安装mysql
- Eclipse中Project的属性Deployment Assembly(部署程序集)消失了,不存在了,去哪儿了
- opencv知识点
- 一道八进制的编程题,在本地运行结果正常,在牛客网提交编译提示输出错误
- 素数分解 (2016_6)
- 山东省第八届 ACM 省赛 company (贪心、水)
- Spring中使用@Pointcut出现IllegalArgumentException
- opencv之仿射与透视变换总结
- qml ListModel与Repeater编写重复控件界面
- SpringMVC+MyBatis+MySql环境搭建
- Centos 设置tomcat开机启动
- android选取linux作为内核的原因
- 在Linux上安装字体
- LeetCode刷题(C++)——Count and Say(Easy )