11.2森林冰火人

先把所有的雪人当成都是第一天做的,然后存在优先队列里面,然后从第一天开始算总共化了多少,如果超过当前最小的雪人,那么就把雪人化到0,弹出就好

#include<bits/stdc++.h>
#define sf scanf
#define scf(x) scanf("%lld",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define vi vector<int>
#define mp make_pair
#define pf printf
#define prf(x) printf("%lld\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=a;i>=n;i--)
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
const double eps=1e-6;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1e5+7;
ll sum[N],a[N],tot[N];

struct node
{
	ll id;ll sum;
	node(ll a=0,ll b=0){id=a;sum=b;}
	friend bool operator <(node a,node b)
	{
		return a.sum >b.sum ;
	} 
};

priority_queue<node> v;
int main()
{
	node t;
	mm(sum,0); 
	ll n;scf(n);
	rep(i,1,n+1) scf(tot[i]);
	rep(i,1,n+1) scf(a[i]);
	ll qq=a[1];
	rep(i,2,n+1)
	{
		tot[i]+=qq;
		qq+=a[i];
	}
	rep(i,1,n+1)  v.push(node(i,tot[i]));
	ll sum1,num=0;
	ll now=0;
	rep(i,1,n+1)
	{
		now+=a[i];
		num++;
		sum1=num*a[i];
		while(!v.empty())
		{
			t=v.top();
			if(t.sum <now)
			{
				v.pop();
				num--;
				//sum1-=a[i];
				sum1+=t.sum -now;
			}else
			break;
		}
		if(n!=i)
			pf("%d ",sum1);
		else 
			prf(sum1);
	}
//	rep(i,1,n+1)	prf(tot[i]);
	return 0;
}
posted @ 2018-12-08 13:16  一无所知小白龙  阅读(460)  评论(0编辑  收藏  举报