当前位置: 代码迷 >> 综合 >> 第八届ACM山东省赛 J company
  详细解决方案

第八届ACM山东省赛 J company

热度:5   发布时间:2023-12-11 17:40:42.0

问题 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 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?

输入

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;
}