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<iostream>
2 #include<bits/stdc++.h>
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()<sum[i]){
22 ans+=(q.top()-sum[i-1]);
23 q.pop();
24 }
25 ans+=c[i]*q.size();
26 cout<<ans<<' ';
27 }
28 cout<<endl;
29 return 0;
30 }

Codeforces-470 div2 C题的更多相关文章

  1. codeforces #262 DIV2 B题 Little Dima and Equation

    题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...

  2. codeforces 260 div2 C题

    C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么: if(a[i] != a[i-1]+1)   dp[i] = cnt[a[i]]*a[i] + dp[ ...

  3. codeforces 260 div2 B题

    打表发现规律,对4取模为0的结果为4,否则为0,因此只需要判断输入的数据是不是被4整出即可,数据最大可能是100000位的整数,判断能否被4整出不能直接去判断,只需要判断最后两位(如果有)或一位能否被 ...

  4. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  5. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  8. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  9. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  10. codeforces 407 div1 B题(Weird journey)

    codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满 ...

随机推荐

  1. 《小白WEB安全入门》03. 漏洞篇

    @ 目录 SQL注入和简单绕过原理 什么是SQL 什么是SQL注入 XSS漏洞原理 什么是XSS XSS分类 NOSQL注入 什么是NOSQL CSRF原理 什么是CSRF 网络摄像头入侵原理 什么是 ...

  2. 【故障公告】一而再,再而三,三翻四复:数据库服务器 CPU 100%

    会员救园,故障捣乱,每当困难时,故障们总是喜欢雪上加霜过来考验你. 今天下班前 17:43~17:47 期间,园子的 SQL Server 数据库服务器突然出现 CPU 100% 问题. 发现问题后, ...

  3. 基于 LLM 的知识图谱另类实践

    本文整理自社区用户陈卓见在「夜谈 LLM」主题分享上的演讲,主要包括以下内容: 利用大模型构建知识图谱 利用大模型操作结构化数据 利用大模型使用工具 利用大模型构建知识图谱 上图是之前,我基于大语言模 ...

  4. 解决SVN死锁问题

    svn执行clean up后出现提示:svn cleanup failed–previous operation has not finished; run cleanup if it was int ...

  5. textarea自动适应高度

    textarea自动适应高度,兼容IE/Firefox.chrome 代码:<textarea name="textarea" id="textarea" ...

  6. 主动写入流对@ResponseBody注解的影响

    问题回溯 2023年Q2某日运营反馈一个问题,商品系统商家中心某批量工具模板无法下载,导致功能无法使用(因为模板是动态变化的) 商家中心报错(JSON串): {"code":-1, ...

  7. pandas -- DataFrame的级联以及合并操作

    博客地址:https://www.cnblogs.com/zylyehuo/ 开发环境 anaconda 集成环境:集成好了数据分析和机器学习中所需要的全部环境 安装目录不可以有中文和特殊符号 jup ...

  8. c++枚举详细介绍以及具体用法

    C++ 中的枚举(Enumeration)是一种用于定义命名常量集合的数据类型.枚举可以提高代码的可读性和可维护性,让您可以使用有意义的名称来表示特定的取值,而不必使用原始的数字常量. 枚举的基本语法 ...

  9. 爬虫系列——Beautifulsoup4

    文章目录 一 介绍 二 基本使用 三 遍历文档树 四 搜索文档树 五 修改文档树 六 总结 ​ 一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能 ...

  10. C#学习笔记--变量类型的转换

    变量类型的转化: 转换原则 同类型的大的可以装小的,小类型的装大的就需要强制转换. 隐式转换: 同种类型的转换: //有符号 long-->int-->short-->sbyte l ...