第八届ACM山东省赛 J company
来源:互联网 发布:python md5解密算法 编辑:程序博客网 时间:2024/05/18 00:42
问题 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山东省赛 J company
- ACM 第八届山东省赛 J company SDUT 3902
- 山东省第八届ACM省赛 J 题(company)
- 第八届山东省赛题 J company (贪心,水)
- 山东省第八届acm省赛 company
- 贪心算法之子段和,山东省第八届acm大赛J题company,SDUT3902
- 山东省第八届ACM省赛J题company(C-DP,贪心)
- 山东省第八届ACM省赛 J 题 company(两种思路) 解答
- 山东省第八届 ACM 省赛 company (贪心、水)
- 山东省第八届acm大赛 J题 (SDUT 3902)
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛 J
- 山东省第八届ACM省赛G和J
- 第八届acm山东省赛总结
- 第八届山东省ACM省赛总结
- 第八届山东省acm省赛总结
- 第七届ACM山东省赛-J Execution of Paladin
- acm省赛题--J company
- 第八届山东省ACM省赛比赛感想
- 【React Native开发01】React Native从环境搭建到项目生成这一篇就够了
- apache和nginx那点事儿--阻塞和异步(非常清楚)
- maven引入ojdbc
- 2017.05.11-1新建IDEA项目
- Java 匿名类详解
- 第八届ACM山东省赛 J company
- nginx源码分析--数组
- linux 环境搭建solr5.5.4搜索服务
- Nicescroll滚动条插件的用法
- 多线程的应用场景
- Java文件流
- 给定按升序排序的整数数组,找到给定目标值的起始和终止位置。 您的算法的运行时复杂度必须是O(log n)的顺序。
- Unicode
- Android自定义动画酷炫的提交按钮