Optiver sponsored problem.

After years of hard work Optiver has developed a mathematical model that allows them to predict wether or not a company will be succesful. This obviously gives them a great advantage on the stock market.

In the past, Optiver made a deal with a big company, which forces them to buy shares of the company according to a fixed schedule. Unfortunately, Optiver's model has determined that the company will go bankrupt after exactly n days, after which their shares
will become worthless.

Still, Optiver holds a large number of sell options that allows them to sell some of the shares before the company goes bankrupt. However, there is a limit on the number of shares Optiver can sell every day, and price Optiver receives for a share may vary
from day to day. Therefore, it is not immediately clear when Optiver should sell their shares to maximize their profit, so they asked you to write a program to calculcate this.

Input

On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

One line with an integer n (1 <= n <= 100 000): the number of days before the company goes bankrupt.

n lines with three integers xi (0 <= xi <= 100),
pi (0 <= pi <= 100) and mi (0 <=
mi <= 10 000 000): the number of shares Optiver receives on day i, the (selling) price per share on day
i, and the maximum number of shares Optiver can sell on day i, respectively.

Output

For each test case:

One line with the maximum profit Optiver can achieve.

Sample Input

1

6

4 4 2

2 9 3

2 6 3

2 5 9

2 2 2

2 3 3

Sample Output

76

题意:有n张股票,给出每天股票的买进数量。当天的股票价格和当天最大抛出量,第i天得到的股票当天能够不抛,能够留到以后抛。

问这n天最多能卖多少钱?

思路:贪心。从后往前贪心,最后一天的股票当然仅仅能在最后一天卖出。第i天的能够在第i天及以后卖出,那么就能够维护一个优先队列来存放第i天及以后的天数中抛出量不为零的日期(价格高的优先)。那抛出第i天时先从优先队列中取出价格最高的。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map> #define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1) #define eps 1e-8
//typedef __int64 ll; #define fre(i,a,b) for(i = a; i <b; i++)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define bug pf("Hi\n") using namespace std; #define INF 0x3f3f3f3f
#define N 100005 int r[N],p[N],s[N];
int n; struct stud{
int p,num;
friend bool operator < (stud a,stud b)
{
return a.p<b.p;
}
}; priority_queue<stud>q; void solve()
{
int i,j;
while(!q.empty()) q.pop(); int ans=0; struct stud cur; for(i=n-1;i>=0;i--)
{
cur.num=s[i];
cur.p=p[i];
q.push(cur); while(!q.empty()&&r[i])
{
cur=q.top(); q.pop(); if(cur.num>r[i])
{
ans+=cur.p*r[i];
//pf("%d %d\n",cur.p,r[i]);
cur.num-=r[i];
r[i]=0;
q.push(cur);
}
else
{
ans+=cur.p*cur.num;
r[i]-=cur.num;
// pf("%d %d\n",cur.p,cur.num); }
} } pf("%d\n",ans);
}
int main()
{
int i,j,t;
sf(t);
while(t--)
{
sf(n);
fre(i,0,n)
sfff(r[i],p[i],s[i]);
solve();
}
return 0; }

最新文章

  1. 利用poi导出Excel
  2. 关于目录路径path
  3. 为sproto手写了一个python parser
  4. 第二章 centos安装maven
  5. Maven初步搭建 (一)
  6. php或js判断网站访问者来自手机或者pc
  7. Django环境搭建和项目创建
  8. 九度OJ题目1003:A+B
  9. Spring Cloud Eureka基本概述
  10. Redis-06.Cluster
  11. 负载(Load)分析及问题排查
  12. 初识nginx——内存池篇
  13. 洛谷p1072 gcd,质因数分解
  14. Excel--数据透视图
  15. python+Selenium 环境搭建
  16. idea linux 启动权限不足的问题
  17. anu - proptypes
  18. activeMQ 持久化配置
  19. JPA error org.hibernate.AnnotationException: No identifier specified for entity
  20. oozie调度中的重试和手工rerun一个workflow

热门文章

  1. object-c的异常处理机制
  2. DCI:The DCI Architecture: A New Vision of Object-Oriented Programming
  3. TOP命令监视系统任务及掩码umask的作用
  4. Androidclient与服务端交互之登陆演示样例
  5. Eclipse搭建Gradle环境
  6. Python学习 —— 阶段综合练习二
  7. javascript实现浏览器窗口传递参数
  8. JSP学习笔记(二):动作元素
  9. linux 的命令 -exec 的使用
  10. 文件及文件夹更改通知/监测软件TheFolderSpy