一 原题

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.

二 分析

题意:每天给你体积为V(i)的一堆雪,每天所有的雪堆会融化T(i)(体积不会为负)。求1-N天内每天融化的雪的体积。1=<N<=1e5,0<=V(i), T(i) <= 1e9

思路:暴力的做法是O(n^2)的。一个更好的做法是:维护T的前缀和Pre,Pre(i)=T(1)+T(2)+...+T(i-1)。对于第i天新增的雪堆,不妨假设它第一天就存在,那么它的初始体积为V'(i)=V(i)+Pre(i-1),在第k天(k>=i)如果V'(i)<=Pre(k),那么这堆雪融化完,在第k天它融化的体积为V'(i)-Pre(k-1),否则就是T(k)。用一个multiset维护目前所有的V',总复杂度O(n*lgn)。

三 代码

#include <cstdio>
#include <set>#define LL long longusing std::multiset;const int maxn = 1e5 + 10;int n, v[maxn], t[maxn];
LL ans = 0, pre[maxn];
multiset<LL> s;int main() {scanf("%d", &n);for (int i = 1; i <= n; i++) scanf("%d", &v[i]);for (int i = 1; i <= n; i++) scanf("%d", &t[i]);for (int i = 1; i <= n; i++) {ans = 0;s.insert(v[i] + pre[i - 1]);pre[i] = pre[i - 1] + t[i];while (!s.empty() && *s.begin() <= pre[i]) {ans += *s.begin() - pre[i - 1];s.erase(s.begin());}ans += s.size() * t[i];printf("%lld ", ans);}return 0;
}

cf 923B Producing Snow相关推荐

  1. codeforces 948C / 923B Producing Snow 【优先队列+思维】

    戳我 传送至 Producing Snow 戳我 到参考网站 **题意:**每天产生一堆雪,大小为v[i]个单位体积,然后每天对应一个数值a[i]代表当天温度,然后剩下的每一堆的雪都会减少这个温度的数 ...

  2. Codeforces Round #470 (rated, Div. 2 C. Producing Snow(思维)

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

  3. 【二分】Producing Snow @Codeforces Round #470 Div.2 C

    time limit per test: 1 second memory limit per test: 256 megabytes Alice likes snow a lot! Unfortuna ...

  4. Producing Snow

    题解:这道题暴力可以出答案,但是会tle tle代码: #include <iostream>using namespace std; const int maxn = 1e5 + 10; ...

  5. 2018.12.05 codeforces 948C. Producing Snow(堆)

    传送门 维护一个堆. 每次先算出一个都不弹掉的总贡献. 然后把要弹掉的弹掉,并减去它们对应的贡献. 代码: #include<bits/stdc++.h> #define ri regis ...

  6. Codeforces 923 B. Producing Snow

    http://codeforces.com/contest/923/problem/B 题意: 有n天,每天产生一堆体积为Vi的雪,每天所有雪堆体积减少Ti 当某一堆剩余体积vi<=Ti时,体积 ...

  7. Producing Snow CodeForces - 948C 优先队列+思维

    题目链接:https://vjudge.net/problem/CodeForces-948C 转自:https://blog.csdn.net/doncoder/article/details/81 ...

  8. CF923B Producing Snow 堆/优先队列

    cf938b 题意每天会产生Vi的雪,每天会融化Ti的雪,所有雪互相独立,V≤0就会消失每天会产生V_i的雪,每天会融化T_i的雪,所有雪互相独立,V\leq0就会消失每天会产生Vi​的雪,每天会融化 ...

  9. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

最新文章

  1. 损失函数的可视化:浅论模型的参数空间与正则
  2. JAVA 连接MYSQL数据库操作
  3. 【Ubuntu】 Ubuntu16.04搭建Samba服务
  4. nginx http子模块conf的初始化
  5. Linux 命令之 make -- GNU的工程化编译工具
  6. 用智能墨水打造超灵敏传感器 “写”到哪里感知就到哪里...
  7. 关于饿了么ui框架的使用之Form 表单的应用
  8. 242种颜色样式、中英文名称及十六进制的值
  9. 【c语言】算数转换解析+试题
  10. selenium入门详细指南(附淘宝抢购案例)
  11. 【数学】微分(Differential)的定义,微分与导数的区别
  12. 读《人性的优点》有感
  13. Ubports安装和使用gedit和ros等记录(仅供参考)
  14. NI无线通信与射频技术学习资源汇总
  15. 给mongoose find()/findOne()查询的结果添加额外的属性
  16. 推荐好用的开源 Docker 工具
  17. [学习记录] SpringBoot 5. 配置文件
  18. 「经验」漫画人体基本结构画法
  19. 【ADUIO音频测试与认证】什么是耳机声压?耳机做CE要做声压测试标准是什么?
  20. 网站建设如何做好页面布局合理

热门文章

  1. PHP面向对象继承的概念
  2. 应急响应 - Webshell 处理 15
  3. ESP32E基于Thonny——python框架,PC端进行局域网控制led亮灭
  4. IOI2017 古书books
  5. Linux pip2 安装
  6. 揭秘字节跳动埋点数据实时动态处理引擎(附源码)
  7. AngularJS 实践:应用开发 :: ENA13 价格条码-(三)
  8. android 常用网址(持续更新)
  9. 火车头采集:高效数据采集工具的介绍
  10. c语言顺序栈完整程序,顺序栈的基本操作(C语言)