ACM 第八届山东省赛 J company SDUT 3902

来源:互联网 发布:python 爬虫框架 编辑:程序博客网 时间:2024/06/08 09:59



题目再现链接:点击打开链接

company

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

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 ival.
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

“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

贪心算法 ,只能用一个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*/