博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces-470 div2 C题
阅读量:5876 次
发布时间:2019-06-19

本文共 2828 字,大约阅读时间需要 9 分钟。

C. Producing Snow
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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
Copy
3 10 10 5 5 7 2
output
5 12 4
input
Copy
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.

题目大意:就是求每天会融化多少雪。

思路:这题目两种思路

1、二分查找第i堆雪什么时候融化。

2、优先队列+前缀和 (优先队列也可以用multiset )

开始我只想到是优先队列,但是怎么处理那些剩下的雪没有好的方法。

后面又想到了是前缀和,但是又没和优先队列联系起来。

AC代码

1 #include
2 #include
3 #define ll long long 4 using namespace std; 5 priority_queue < ll , vector < ll > , greater < ll > > q; 6 ll a[100500]; 7 ll c[100500]; 8 ll sum[100500]; 9 int main(){10 ll n;11 cin>>n;12 for(ll i=1;i<=n;i++)13 scanf("%d",a+i);14 for(ll i=1;i<=n;i++){15 scanf("%d",c+i);16 sum[i]=c[i]+sum[i-1];17 }18 for(ll i=1;i<=n;i++){19 q.push(a[i]+sum[i-1]); //关键一步!!!让新加的雪堆变成第一天就已经放置的雪堆!!!20 ll ans=0;21 while(!q.empty()&&q.top()

 

转载于:https://www.cnblogs.com/ISGuXing/p/8597701.html

你可能感兴趣的文章
windows10 chrome 调试 ios safari 方法
查看>>
Netty 4.1.35.Final 发布,经典开源 Java 网络服务框架
查看>>
详解Microsoft.AspNetCore.CookiePolicy
查看>>
SCDPM2012 R2实战一:基于SQL 2008 R2集群的SCDPM2012 R2的安装
查看>>
SQL SERVER中字段类型与C#数据类型的对应关系
查看>>
Linux lsof命令详解
查看>>
SVG path
查看>>
js判断checkbox是否选中
查看>>
多系统盘挂载
查看>>
MySQL函数怎么加锁_MYSQL 函数调用导致自动生成共享锁问题
查看>>
MR1和MR2的工作原理
查看>>
Eclipse中修改代码格式
查看>>
GRUB Legacy
查看>>
关于 error: LINK1123: failure during conversion to COFF: file invalid or corrupt 错误的解决方案...
查看>>
python实现链表
查看>>
java查找string1和string2是不是含有相同的字母种类和数量(string1是否是string2的重新组合)...
查看>>
Android TabActivity使用方法
查看>>
Eclipse的 window-->preferences里面没有Android选项
查看>>
《麦田里的守望者》--[美]杰罗姆·大卫·塞林格
查看>>
遇到的那些坑
查看>>