[CodeForces948C]Producing Snow(优先队列)

Description

题目链接

Solution

将温度做一个前缀和,用一个优先队列依次处理一遍

思路还是很简单的

Code

#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long
#define N 100010
using namespace std;

priority_queue<ll,vector<ll>,greater<ll> > q;
int n,A[N],T[N];
ll sum[N];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&A[i]);
	for(int i=1,t;i<=n;++i){scanf("%d",&T[i]);sum[i]=sum[i-1]+T[i];}
	for(int i=1;i<=n;++i){
		ll Ans=0;
		q.push(A[i]+sum[i-1]);
		while(!q.empty()&&q.top()<=sum[i]){
			Ans+=q.top()-sum[i-1];
			q.pop();
		}
		Ans+=q.size()*1ll*T[i];
		printf("%I64d ",Ans);
	}
	return 0;
}
posted @ 2018-03-12 19:34  void_f  阅读(331)  评论(0编辑  收藏  举报