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

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 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
02 #include
03 #include
04 #include
05 #include
06 #include
07 #include
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
32         {
33             sum[i]=sum[i-1]+v[i];
34             ans+=(i+1)*v[i];
35         }
36         for(int i=0; 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<
44     return 0;
45 }
46  
47 /***************************************************

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

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

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

01 #include
02 #include
03 #include
04 #include
05 #include
06 #include
07 #include
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
30     {
31         k=1;
32         sum=0;
33         for(j=i;j
34         {
35             sum+=(v[j]*k);
36             k++;
37         }
38         if(sum>max)
39             max=sum;
40     }
41     cout<
42     return 0;
43 }
44  

你可能感兴趣的:(练习,练习)