ACM 第八届山东省赛 J company SDUT 3902
来源:互联网 发布:python 爬虫框架 编辑:程序博客网 时间:2024/06/08 09:59
题目再现链接:点击打开链接
company
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 61 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.
Author
贪心算法 ,只能用一个for循环 并且 用long long int 数据量会非常大
倒着 从后面考虑 叠楼梯
层数代表天数 有前到后依次增加
代码:
#include <iostream>#include <algorithm>#include <cmath>#include <cstring>#include <stdio.h>#include <string>typedef long long ll;using namespace std;ll a[1000000];ll dp[1000000];int main(){ int k,i,j,n; while(cin>>n) { memset(a,0,sizeof(a)); memset(dp,0,sizeof(dp)); for(i=0;i<n;i++) { cin>>a[i]; } for(i=0,j=0;i<n;i++) { cin>>k; while(k>1) { a[n+j]=a[i]; j++; k--; } } sort(a,a+n+j); int len=n+j; ll ans=0; ll dsum=0; //dp[len-1]=a[len-1]; for(i=len-1;i>=0;i--) { dsum+=a[i]; if(dsum<0) break; dp[i]=dp[i+1]+dsum; if(ans<dp[i]) ans=dp[i]; } cout<<ans<<endl; } return 0;}/*5-1 -1 -1 -1 11 1 1 1 1*/
- ACM 第八届山东省赛 J company SDUT 3902
- 第八届ACM山东省赛 J company
- 山东省第八届acm大赛 J题 (SDUT 3902)
- 山东省第八届ACM省赛 J 题(company)
- 第八届山东省赛题 J company (贪心,水)
- 山东省第八届acm省赛 company
- 贪心算法之子段和,山东省第八届acm大赛J题company,SDUT3902
- 山东省第八届ACM省赛J题company(C-DP,贪心)
- 山东省第八届ACM省赛 J 题 company(两种思路) 解答
- ACM 第八届山东省赛 F quadratic equation SDUT 3898
- ACM 第八届山东省赛 I Parity check SDUT 3901
- 山东省第八届 ACM 省赛 company (贪心、水)
- 山东省第一届ACM省赛 J SDUT 2160 Jerry Mouse
- 山东省第八届acm大赛 F题 (SDUT 3898)
- 山东省第八届acm大赛 G题 (SDUT 3899)
- 山东省第八届acm大赛 I题 (SDUT 3901)
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛 J
- 山东省第八届ACM省赛G和J
- jQuery选择器之id选择器
- 安卓写入文件读取文件初步
- Java学习笔记(十四)--IO流
- ue4编辑器中StaticMesh边缘高亮
- Android 自定义View
- ACM 第八届山东省赛 J company SDUT 3902
- c++学习(四)
- 简单动态加载磁盘文件----删除功能
- 反斜杠转义字符不转义解决方法
- POJ
- Java:简单的RMI
- 验证码生成及使用
- Activity的生命周期
- 欢迎使用CSDN-markdown编辑器