第八届山东省赛题 J company (贪心,水)
来源:互联网 发布:有sql注入漏洞的网站 编辑:程序博客网 时间:2024/06/05 23:05
2018: J company
时间限制: 1 Sec 内存限制: 128 MB提交: 4 解决: 4
[提交][状态][讨论版]
题目描述
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 pricechanges, for any goods sold on dayi, 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 untilyou can't or don't want to do so. If you are allowed to leave some goodsunsold, what's the max total benefit you can get in the end?
输入
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 an integer in a single line, indicating the maxtotal benefit.
Hint: sell goods whose price with order as -1, 5, 6, 6, thetotal benefit would be -1*1 + 5*2 + 6*3 + 6*4 = 51.
样例输入
4-1 -100 5 61 1 1 2
样例输出
51
列出每种物品的的价值以及数量,要求每天只能卖一个商品。
我们先把所有商品的价格存在数组里,从小到大排序。然后在算买全部商品得到的钱数ans
再从数组的最左边开始枚举,逐个删去,在过程中取ans的最大值
删的过程中,会改变其他商品卖的天数,。。。。
#include<cstdio>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>using namespace std;typedef long long LL;const int MAX=100000+5;struct ss{ int cnt,val;};int re[MAX];int sum[MAX];int main(){ int n; while(cin>>n) { int flag=0; ss num[1005]; memset(re,0,sizeof(re)); memset(sum,0,sizeof(sum)); for(int i=0; i<n; i++) { scanf("%d",&num[i].val); } for(int i=0; i<n; i++) { scanf("%d",&num[i].cnt); } for(int i=0; i<n; i++) { for(int j=0; j<num[i].cnt; j++) { re[flag++]=num[i].val;///把所有商品的所有价格存到数组里 } } sort(re,re+flag); sum[0]=re[0];///sum数组记录商品价格和 LL ans=re[0];///ans为最终答案 for(int i=1; i<flag; i++) { sum[i]=re[i]+sum[i-1]; ans+=(i+1)*re[i]; } for(int i=0; i<flag; i++)///从数组最左边开始枚举,逐一删去 { LL ls=ans-re[i]-sum[flag-1]+sum[i];///改变的价格 if(ls>ans)///取过程中的最大值 ans=ls; else break; } printf("%lld\n",ans); } return 0;}
- 第八届山东省赛题 J company (贪心,水)
- 山东省第八届ACM省赛J题company(C-DP,贪心)
- 第八届ACM山东省赛 J company
- 山东省第八届ACM省赛 J 题(company)
- 山东省第八届 ACM 省赛 company (贪心、水)
- 贪心算法之子段和,山东省第八届acm大赛J题company,SDUT3902
- ACM 第八届山东省赛 J company SDUT 3902
- 山东省第八届ACM省赛 J 题 company(两种思路) 解答
- 山东省第八届acm大赛 J题 (SDUT 3902)
- 山东省第八届acm省赛 company
- 第八届山东省赛 sdut 3903 CF(贪心+dp)
- 山东省第八届acm省赛K题 贪心+dp
- 2017第八届浪潮杯山东省赛 K题 codeforces 贪心+背包
- 第八届山东省赛题->Parity check
- 第八届山东省赛题->CF
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛 J
- 山东省第八届ACM省赛G和J
- Execution of Paladin(山东省第七届acm j题)
- HashSet,HashMap这些集合的toString方法拼成字符串竟然有空格,坑死我了。
- JAVA开发之 15-JAVA标识符
- CyblicBarrier使用
- 关于Visual Studio 2013 编译 multi-byte character set MFC程序出现 MSB8031 错误的解决办法
- 25个沙盘工作坊,深度解密亿级用户产品背后的研发管理实践
- 第八届山东省赛题 J company (贪心,水)
- ReactNative打发布包流程(Android)
- 快速排序(Quick Sort) Java实现
- GPU CPU NPU
- .net mvc5 (一)
- nginx虚拟机配置
- 解决因mouseover,mouseout冒泡产生的闪烁问题+兼容性问题
- android源码-智能语音输入查询天气app
- 代码和作品分享