第八届ACM山东省赛 J company
2017-05-09 17:25
344 查看
问题 J: J company
时间限制: 1 Sec 内存限制: 128 MB提交: 2 解决: 2
[提交][状态][讨论版]
题目描述
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 dayi, if its direct benefit isval, 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?
输入
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 max total benefit.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.
样例输入
4-1 -100 5 61 1 1 2
样例输出
51
提示
分析:比赛时因为一个坑题心态崩了没看,很简单,先排序,然后二分查找到正数的位置,求和之后会得出一个值,然后用二重循环从前向后找,直到负数加权和不超过之前的那个值,因为只要不超过,后面正数的数翻倍后结果肯定比之前大。然后从找到的负数位置向后扫即可。
#include <bits/stdc++.h> using namespace std; vector <int> a; int main() { int n; cin>>n; int q; for(int i=0; i<n; i++) { scanf("%d",&q); a.push_back(q); } for(int i=0; i<n; i++) { scanf("%d",&q); if(q>1) { for(int j=0; j<q-1; j++) { a.push_back(a[i]); } } } sort(a.begin(),a.end()); int pos=upper_bound(a.begin(),a.end(),0)-a.begin(); long long sum=0; for(int i=pos; i<a.size(); i++) { sum+=a[i]; } bool ok; int record; for(int i=0; i<pos; i++) { int k=1; for(int j=i; j<pos; j++) { long long sum2=0; ok=0; sum2+=a[j]*k; k++; if(abs(sum2)>sum) { ok=1; break; } } if(ok==0) { record=i; break; } } long long ans=0; int cnt=1; for(int i=record; i<a.size(); i++) { ans+=a[i]*cnt; cnt++; } cout<<ans; return 0; }
相关文章推荐
- 山东省第八届 ACM 省赛 sum of power (求和、水)
- 第八届acm山东省赛总结
- 山东省第八届ACM省赛 K 题 CF (排序01背包)
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛I
- 山东省第八届 ACM 省赛 fireworks (组合数+逆元)
- 山东省第八届 ACM 省赛 G sum of power (简单快速幂)
- 山东省第八届ACM省赛 K 题(CF)
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛 J
- 山东省第八届acm省赛 HEX
- 2017年ACM第八届山东省赛A题:Return of the Nim
- ”浪潮杯”山东省第八届ACM大学生程序设计竞赛 K CF【01背包 + 贪心】
- 山东省第八届ACM大赛I题题解
- 2017年山东省第八届ACM大学生程序设计竞赛 C fireworks(sdut 3895) 逆元求组合数
- SDUT 3895 (山东省第八届ACM省赛C题) fireworks 杨辉三角+乘法逆元
- 2017年ACM第八届山东省赛F题:quadratic equation(离散数学蕴含式)
- 第八届山东省ACM大学生程序设计竞赛总结
- 2017年山东省第八届ACM大学生程序设计竞赛总结
- 贪心算法之子段和,山东省第八届acm大赛J题company,SDUT3902
- ACM 第八届山东省赛 F quadratic equation SDUT 3898
- 2017年ACM第八届山东省赛G题:sum of power