acm题stock

来源:百度知道 编辑:UC知道 时间:2024/06/22 15:39:43
Background
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 &l

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct stock
{
long long x,p,m;
}a[100005];

struct cmp
{
bool operator()(const stock & a,const stock & b)const
{
return a.p < b.p;
}
};

int main()
{
int t,n;
long long ans;
stock temp;
cin>>t;
while(t--)
{
ans=0;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i].x>>a[i].p>>a[i].m;
priority_queue< stock,vector<stock>,cmp >q;
if(a[n-1].m>a[n-1].x)
{
ans+=a[n-1].p*a[n-1].x;
a[n-1].m-=a[n-1].x;
q.push(a[n-1]);
}
else
ans+=a[n-1].p*a[n-1].m;
for(int i=n-2;i>=0;i--)