山东省第八届acm大赛 J题 (SDUT 3902)
来源:互联网 发布:淘宝开店要2张银行卡 编辑:程序博客网 时间:2024/06/06 02:25
company
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 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?
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.
WA了无数次 最后结果记住要用 long long
AC代码:
#include <stdio.h> #include <algorithm> using namespace std; int cmp(int a,int b){ return a>b; } int main (){ int num[1005]; int a[100010]; int n; scanf ("%d",&n); for (int i=1;i<=n;i++){ scanf ("%d",&num[i]); } int len=0; int v; for (int i=1;i<=n;i++){ scanf ("%d",&v); while (v--){ a[len++]=num[i]; } } sort(a,a+len,cmp); //printf("%d\n",len); long long maxn=-999999999; int flag=1; for (int k=len;k>0&&flag;k--)// 要有flag标志位 不然会超时 { flag=0; long long sum=0; for (int i=0;i<=k;i++){ sum+=(a[i]*(k-i)); } if (maxn<sum){ flag=1; maxn=sum; } } printf ("%lld\n",maxn); return 0; }
- 山东省第八届acm大赛 J题 (SDUT 3902)
- 山东省第八届acm大赛 F题 (SDUT 3898)
- 山东省第八届acm大赛 G题 (SDUT 3899)
- 山东省第八届acm大赛 I题 (SDUT 3901)
- ACM 第八届山东省赛 J company SDUT 3902
- 贪心算法之子段和,山东省第八届acm大赛J题company,SDUT3902
- 山东省第八届ACM省赛 J 题(company)
- 第八届ACM山东省赛 J company
- 山东省第八届ACM大赛I题题解
- 山东省第八届ACM省赛J题company(C-DP,贪心)
- 山东省第八届ACM省赛 J 题 company(两种思路) 解答
- 山东省第一届ACM省赛 J SDUT 2160 Jerry Mouse
- SDUT 3896 HEX 山东第八届ACM大赛D题(组合数学)
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
- ACM 第八届山东省赛 F quadratic equation SDUT 3898
- ACM 第八届山东省赛 I Parity check SDUT 3901
- “浪潮杯”山东省第八届ACM大学生程序设计竞赛 J
- 山东省第八届ACM省赛G和J
- 山东省第八届acm大赛 F题 (SDUT 3898)
- Ubuntu图形界面介绍和远程VNC连接
- Linux 漫谈开源许可证/红帽认证
- ModBus/TCP协议分析
- vlc分析之基础结构
- 山东省第八届acm大赛 J题 (SDUT 3902)
- [LeetCode]15.threeSum
- 山东省第八届acm大赛 G题 (SDUT 3899)
- USACO
- Facebook Shimmer 实现原理
- SlidingMenu侧边栏的实现
- 百万级访问网站前期的技术准备
- 山东省第八届acm大赛 I题 (SDUT 3901)
- 今日LeetCode--21