company
来源:互联网 发布:aim聊天软件 编辑:程序博客网 时间:2024/05/16 13:51
题目描述
There are n kinds of goods in the company, with each of them has a inventory of cnti and direct unit benefit vali. 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 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 <algorithm>#include <iostream>#include <cstring>#include <cstdio>#include <string>using namespace std;#define mod 1000000007#define INF 0x3f3f3f3f#define N 1000int val[N],cnt[N];int b[N*100];int sum[N*100];int main(){ int n; scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%d",&val[i]); for(int i = 0; i < n; i++) scanf("%d",&cnt[i]); int k = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < cnt[i]; j++) { b[k++] = val[i]; } } k--; sort(b,b+k+1); // for(int i = 0;i <= k;i++) // printf("%d ",b[i]); // cout << endl; long long ans = 0,t; for(int i = 0; i <= k; i++) { if(i == 0) { sum[i] = b[i]; ans = b[i]; continue; } sum[i] = sum[i-1] + b[i]; ans += (i + 1) * b[i]; } for(int i = 0; i <= k; i++) { t = ans - (sum[k] - sum[i] + b[i]); if(t > ans) ans = t; } printf("%lld\n",ans); return 0;}
- company
- company
- company
- company
- company
- Company Meeting
- Company Introduction
- Company Code
- TIOBE Company
- company-mode
- Shredding Company
- Mail - Company
- zoj1694_Shredding Company
- PopCap Company
- poj_1416Shredding Company
- Company Identifiers
- Prefer company
- Shredding Company
- Remove Duplicates from Sorted Array II
- 看起来像它——图像搜索其实也不难
- 标准IO缓存
- js 时间-date
- 一些oracle相关的链接
- company
- 循环,数组,参数变量
- HDU1556 Color the ball
- java实现线性表中的链式存储
- c++————学习记录(一)
- chaofn python中List添加、删除元素的几种方法
- Codeforces 1B. Spreadsheets
- 判断栈的压入、弹出序列
- C语言 求最大公约数的三种方法,利用最大公约数求最小公倍数,通过分解质因数法来验证