Codeforces-470 div2 C题
C. Producing Snowtime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputOutput a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.
ExamplesinputCopy3
10 10 5
5 7 2output5 12 4inputCopy5
30 25 20 15 10
9 10 12 4 13output9 20 35 11 25NoteIn 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题的更多相关文章
- codeforces #262 DIV2 B题 Little Dima and Equation
题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...
- codeforces 260 div2 C题
C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么: if(a[i] != a[i-1]+1) dp[i] = cnt[a[i]]*a[i] + dp[ ...
- codeforces 260 div2 B题
打表发现规律,对4取模为0的结果为4,否则为0,因此只需要判断输入的数据是不是被4整出即可,数据最大可能是100000位的整数,判断能否被4整出不能直接去判断,只需要判断最后两位(如果有)或一位能否被 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- codeforces 407 div1 B题(Weird journey)
codeforces 407 div1 B题(Weird journey) 传送门 题意: 给出一张图,n个点m条路径,一条好的路径定义为只有2条路径经过1次,m-2条路径经过2次,图中存在自环.问满 ...
随机推荐
- 如何正确实现一个自定义 Exception
最近在公司的项目中,编写了几个自定义的 Exception 类.提交 PR 的时候,sonarqube 提示这几个自定义异常不符合 ISerializable patten. 花了点时间稍微研究了一下 ...
- springcache+redis实战
前言 有兴趣的同学,可以看我上一篇文章,然后再过来看会比较清楚点:https://www.cnblogs.com/yhc-910/p/14884678.html springcache,简单说,就是用 ...
- tomcat配置域名绑定项目
有时候我们需要根据访问的不同域名,对应tomcat中不同的项目例如:一个网站同时做了两套,pc版和手机版.手机版对应的域名是m.we-going.com,就需要在tomcat配置文件中加入以下代码:& ...
- 给你的模糊测试开开窍——定向灰盒模糊测试(Directed Greybox Fuzzing)综述
本文系原创,转载请说明出处 Please Subscribe Wechat Official Account:信安科研人,获取更多的原创安全资讯 原论文:<The Progress, Cha ...
- WEB组态编辑器插件(BY组态)介绍
BY组态是一款非常优秀的纯前端的[web组态插件工具],采用标准HTML5技术,基于B/S架构进行开发,支持WEB端呈现,支持在浏览器端完成便捷的人机交互,简单的拖拽即可完成可视化页面的设计.可无缝嵌 ...
- 织梦dede邮箱发信配置教程
环境要求 主机465端口是开启和放行的 php扩展openssl是开启的 php扩展sockets是开启的 1.QQ邮箱或者163邮箱.126邮箱,开启SMTP服务,拿到授权码,根据自己的来 QQ邮箱 ...
- Solution -「NOI 2021」轻重边
Description Link. 给出一棵树,初始边权为 \(0\),支持毛毛虫虫体赋 \(1\),虫足赋 \(0\),以及查询路径边权和操作,\(n,m\leqslant 10^5\). Solu ...
- 一些H5对接微信JSSDK的问题记录
这里给大家分享我在实际生活中总结出来的一些知识,希望对大家有所帮助 一.SDK引入 这里提供两套引入流程,一套是vue2.0及其他h5项目,一套是vue3.0的引入流程 不懂的也可以看我之前的一篇详细 ...
- IPv6的基本认识
IPv6 1.IPv6的基本认识 IPv4 位数是 32位,4字节,能够提供的IP地址大约是42亿,但你知道的,如今一个人都不止一个IP地址,看看如今设备的数量及发展速度就知道,所以有了IPv6,IP ...
- socket应用的例子
当使用 C 语言实现 Socket 编程时,可以通过系统提供的网络库来实现网络通信.以下是一个简单的示例,演示了如何创建一个简单的服务器和客户端,实现客户端向服务器发送消息并接收回复的功能. 服务器端 ...