【CodeForces - 948C】【Producing Snow】

版权声明:本人原创,未经许可,不得转载 https://blog.csdn.net/qq_42505741/article/details/82023254

题目:

Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.

Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other.

Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.

You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.

Input

The first line contains a single integer N (1 ≤ N ≤ 105) — the number of days.

The second line contains N integers V1, V2, ..., VN (0 ≤ Vi ≤ 109), where Vi is the initial size of a snow pile made on the day i.

The third line contains N integers T1, T2, ..., TN (0 ≤ Ti ≤ 109), where Ti is the temperature on the day i.

Output

Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.

Examples

Input

3
10 10 5
5 7 2

Output

5 12 4

Input

5
30 25 20 15 10
9 10 12 4 13

Output

9 20 35 11 25

Note

In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.

题意:给我们 n 天的时间,每天都会有新的雪堆生成,然后每天又会有雪堆消耗,当然每天的消耗是不同的,叫我们输出每天的雪量的消耗。

解题思路:上来确实是很简单,直接暴力求解试一下,但是 很光荣的 T 了,之后一直卡,不知道进展,后来训练结束后,大神的讲解我也没有听的很明白,后来思考了好久,今天终于有些领悟了,来补一下这道题目。

咱们可以对数据进行一下操作,使每天都是第一天,然后就对他们进行操作,看看累计消耗的值,能够撑多久,(优先队列的长度)如果满足条件 ,那么就ans加和 ,(即前边几天都符合的时候),不符合的时候,就说明前边生成的雪堆不足以支撑这些天的消耗了,咱们就从头开始减 直到雪堆完全消耗。

具体啥的见代码

ac代码:

#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
priority_queue<long long int ,vector<long long int >,greater<long long int > >que;
const int N=1e5+5;
int num[N];
long long int res[N];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++)
			scanf("%d",&num[i]);
		long long int ans;
		res[0]=0;
		for(int i=1;i<=n;i++)
		{
			ans=0;
			scanf("%I64d",&res[i]);	
			res[i]+=res[i-1];//累计前几天 的消耗和 
			que.push(num[i]+res[i-1]);//将今天产生的和昨天消耗的加在一起,更改为第一天的状态 
			while(!que.empty()&&res[i]>=que.top())
			{//如果队列内的雪堆撑不住消耗的话,就只加上不满足条件的雪堆的剩余 
				ans+=que.top()-res[i-1];
				que.pop();
			}
			ans+=que.size()*(res[i]-res[i-1]);//撑过了几天 
			printf("%I64d ",ans);
		}
		printf("\n");
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42505741/article/details/82023254