山东省第八届ACM省赛 J 题(company)
来源:互联网 发布:淘宝联盟用了红包丢单 编辑:程序博客网 时间:2024/05/22 06:21
Problem Description
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 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≤.≤100).
The third line contains n integers cnt1,cnt2,..,cntn(1≤≤100).
Output
Output an integer in a single line, indicating the max total benefit.
Example Input
4
-1 -100 5 6
1 1 1 2
Example Output
51
Hint
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 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≤.≤100).
The third line contains n integers cnt1,cnt2,..,cntn(1≤≤100).
Output
Output an integer in a single line, indicating the max total benefit.
Example Input
4
-1 -100 5 6
1 1 1 2
Example Output
51
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.
题意:商店买东西,有n种商品,每种商品卖出去以后得到的价值是v,每种商品有c件,第i天卖出v价值的商品,得到的价值是i*v,时间是从第一天开始,每天只能卖一件,对于每件商品你可以选择卖或者不卖;
思路:把每件商品都存到一个数组里,排序,找到第一个不是负数的数,记录位置,然后把这个位置之后的(包括它自己)按顺序全卖,然后把这个位置往前移一位,再进行,记录得到的最大的价值;
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define maxn 100010#define INF 0x3f3f3f3fusing namespace std;int d[maxn];int n,v[1010],c[1010];long long sum,MAX;int main(){ scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&v[i]); } for(int i=0; i<n; i++) { scanf("%d",&c[i]); } int ii=1; for(int i=0; i<n; i++) { for(int j=0; j<c[i]; j++) { d[ii++]=v[i]; } } sort(d+1,d+ii); d[0]=-1; //这个地方是为了避免全是正数或者全是负数的情况; d[ii]=1; int xx=0; for(int i=1; i<ii; i++) //找的第一个不是负数的数; { if(d[i]>=0&&d[i-1]<0) { xx=i; break; } } MAX=-INF; for(int i=0; i<xx; i++) //挨个的往前取,并把最大的保存; { int day=1; sum=0; for(int j=xx-i; j<ii; j++) { sum+=day*d[j]; day++; } if(MAX<sum) MAX=sum; } cout<<MAX<<endl; return 0;}
0 0
- 山东省第八届ACM省赛 J 题(company)
- 山东省第八届ACM省赛J题company(C-DP,贪心)
- 山东省第八届ACM省赛 J 题 company(两种思路) 解答
- 第八届ACM山东省赛 J company
- 第八届山东省赛题 J company (贪心,水)
- ACM 第八届山东省赛 J company SDUT 3902
- 山东省第八届acm省赛 company
- 山东省第八届 ACM 省赛 company (贪心、水)
- 贪心算法之子段和,山东省第八届acm大赛J题company,SDUT3902
- 山东省第八届acm大赛 J题 (SDUT 3902)
- 山东省第八届ACM省赛G和J
- 山东省第八届ACM省赛C题
- 山东省第八届ACM省赛A题
- 山东省第八届ACM省赛 I 题(Parity check)
- 山东省第八届ACM省赛 F 题(quadratic equation)
- 山东省第八届ACM省赛 K 题(CF)
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛 J
- Execution of Paladin(山东省第七届acm j题)
- COJ-1005-Binary Search Tree analog
- kafka教程-基本概念
- HDU
- Java三大框架搭建
- boost库简单读写xml
- 山东省第八届ACM省赛 J 题(company)
- 偷换windows窗口过程
- Linux 存储管理 缺页中断和页面换入
- [LeetCode
- HDU 1059 Dividing (多重背包二进制优化)
- 数据结构-C++ 迷宫
- [算法]n阶台阶,一次走一步或两步,有多少种走法?
- K-means KNN AND KD-tree
- [C++]图的邻接矩阵、邻接表及其相互转化和邻接表的广度遍历、深度遍历