“浪潮杯”山东省第八届ACM大学生程序设计竞赛 J

company

Time Limit: 1000MS  Memory Limit: 65536KB
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 6
1 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.

01 #include <iostream>
02 #include<string.h>
03 #include<string>
04 #include<algorithm>
05 #include<stdio.h>
06 #include<cmath>
07 #include<vector>
08 using namespace std;
09 int a[1005],b[1005];
10 vector<int>v;
11 int main()
12 {
13     int i,j,k;
14     int n;
15     cin>>n;
16     for(i=1;i<=n;i++)
17         cin>>a[i];
18     for(i=1;i<=n;i++)
19         cin>>b[i];
20     for(i=1;i<=n;i++)
21     {
22         for(k=1;k<=b[i];k++)
23             v.push_back(a[i]);
24     }
25     sort(v.begin(),v.end());
26     int nn=v.size();
27     int sum[100005];
28     int max=-10000000000;
29     sum[0]=v[0];
30         long long  ans=v[0];
31         for(int i=1; i<nn; i++)//       求
32         {
33             sum[i]=sum[i-1]+v[i];
34             ans+=(i+1)*v[i];
35         }
36         for(int i=0; i<nn; i++)
37         {
38             long long s=ans-v[i]-sum[nn-1]+sum[i];
39             if(s>ans)
40                 ans=s;
41             else break;
42         }
43     cout<<ans<<endl;
44     return 0;
45 }
46  
47 /***************************************************

这个题我写的  做的时候想来个直接的 非常自信的交了 比赛时一直没领悟 这么几个数怎么会超时

自信看看就知道有可能有1000*100个数

这样一个双重循环不超才怪 

01 #include <iostream>
02 #include<string.h>
03 #include<string>
04 #include<algorithm>
05 #include<stdio.h>
06 #include<cmath>
07 #include<vector>
08 using namespace std;
09 int a[1005],b[1005];
10 vector<int>v;
11 int main()
12 {
13     int i,j,k;
14     int n;
15     cin>>n;
16     for(i=1;i<=n;i++)
17         cin>>a[i];
18     for(i=1;i<=n;i++)
19         cin>>b[i];
20     for(i=1;i<=n;i++)
21     {
22         for(k=1;k<=b[i];k++)
23             v.push_back(a[i]);
24     }
25     sort(v.begin(),v.end());
26     int nn=v.size();
27     int sum=0;
28     int max=-10000000000;
29     for(i=0;i<nn;i++)
30     {
31         k=1;
32         sum=0;
33         for(j=i;j<nn;j++)
34         {
35             sum+=(v[j]*k);
36             k++;
37         }
38         if(sum>max)
39             max=sum;
40     }
41     cout<<max<<endl;
42     return 0;
43 }
44  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值