J. Cola
J. Cola
time limit per test
4.0 s
64 MB
standard input
standard output
At Cola factory there is N bottles on a line. Also, there is a machine that pour cola in these bottles one by one. Every thing was working well. Suddenly, the machine started acting in a strange way !!
It started choosing a random bottle and pour a random quantity of cola in this bottle.
When a bottle is full, the rest of the cola goes to the bottle on the right of it, and if it was the last bottle, then the rest of the cola will be wasted .
As an engineer in this factory, you were given the capacity of every bottle in Litters. Also, you know the record of machine moves because it is stored in the Microcontroller memory of the machine. You are asked to compute the amount of wasted cola, and the amount of cola every bottle has at the end.
Your program will be tested on one or more test cases. The first line of the input will be a single integer T the number of test cases. Followed by the test cases.
Every test case starts with two numbers N and M (1 ≤ N ≤ 105), (1 ≤ M ≤ 105) denoting the number of bottles, and the number of moves the machine had did.
Then follow N integers on a line separated by spaces. The integer Ci denotes the capacity of the ith bottle (1 ≤ Ci ≤ 109) where (1 ≤ i ≤ N).
M lines follow denoting the moves. Each line contains two integers X and Y (1 ≤ X ≤ N), (1 ≤ Y ≤ 109) means that the machine poured Yliters of cola in the Xth bottle .
For each test case print two lines.
First line contains the amount of wasted cola.
The second line contains N integers separated by spaces denoting the amount of cola in every bottle at the end.
2
5 3
5 4 3 2 1
3 4
4 4
1 2
6 3
3 4 5 5 6 7
3 3
1 8
5 9
2
2 0 3 2 1
0
3 4 4 0 6 3 题意:n个杯子,第i个杯子容量为a[i],m次操作,每次往杯子x里倒y单位的水,第i个杯子满了之后多余的水就会倒进第i+1个杯子里,如果第n个杯子也满了那么多余的水就浪费,问浪费了多少水 完全按照题目意思模拟肯定是会超时的,所以先不管加可乐的时候会不会漏出,先加进去,加完m次之后,在统一处理大于容量的情况
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<vector>
#include<stack>
#include<math.h>
#define mod 998244353
#define ll long long
#define MAX 0x3f3f3f3f
using namespace std;
struct node
{
ll k;
ll now;
}p[];
int main()
{
ll n,t,m;
cin>>t;
while(t--)
{
cin>>n>>m;
for(ll i=;i<=n;i++)
{
cin>>p[i].k;
p[i].now=;
}
ll x,y;
ll ans=;
for(ll i=;i<m;i++)
{
cin>>x>>y;
p[x].now=p[x].now+y;//wa了好多次,有可能多次都是从同一个瓶子开始加可乐
}
for(ll i=;i<n;i++)
{
if(p[i].now>p[i].k)
{
p[i+].now=p[i+].now+p[i].now-p[i].k;
p[i].now=p[i].k;
}
}
if(p[n].now>p[n].k)
{
ans=p[n].now-p[n].k;
p[n].now=p[n].k;
}
cout<<ans<<endl;
for(ll i=;i<=n;i++)
{
if(i!=n)
cout<<p[i].now<<' ';
else
cout<<p[i].now<<endl;
}
}
return ;
}
J. Cola的更多相关文章
- 【Java并发编程实战】-----“J.U.C”:CAS操作
CAS,即Compare and Swap,中文翻译为"比较并交换". 对于JUC包中,CAS理论是实现整个java并发包的基石.从整体来看,concurrent包的实现示意图如下 ...
- 【Java并发编程实战】-----“J.U.C”:Exchanger
前面介绍了三个同步辅助类:CyclicBarrier.Barrier.Phaser,这篇博客介绍最后一个:Exchanger.JDK API是这样介绍的:可以在对中对元素进行配对和交换的线程的同步点. ...
- 【Java并发编程实战】-----“J.U.C”:CountDownlatch
上篇博文([Java并发编程实战]-----"J.U.C":CyclicBarrier)LZ介绍了CyclicBarrier.CyclicBarrier所描述的是"允许一 ...
- 【Java并发编程实战】-----“J.U.C”:CyclicBarrier
在上篇博客([Java并发编程实战]-----"J.U.C":Semaphore)中,LZ介绍了Semaphore,下面LZ介绍CyclicBarrier.在JDK API中是这么 ...
- 【Java并发编程实战】-----“J.U.C”:ReentrantReadWriteLock
ReentrantLock实现了标准的互斥操作,也就是说在某一时刻只有有一个线程持有锁.ReentrantLock采用这种独占的保守锁直接,在一定程度上减低了吞吐量.在这种情况下任何的"读/ ...
- JAVA并发编程J.U.C学习总结
前言 学习了一段时间J.U.C,打算做个小结,个人感觉总结还是非常重要,要不然总感觉知识点零零散散的. 有错误也欢迎指正,大家共同进步: 另外,转载请注明链接,写篇文章不容易啊,http://www. ...
- Android Studio解决未识别Java文件(出现红J)问题
1.问题:java文件出现了红J的问题,正常情况下应该是显示蓝色的C标识. 2.解决方案:切换到project视图下,找到app这个module里的build.gradle,在android结构里插入 ...
- //给定N个整数序列{A1,A2,A3...An},求函数f(i,j)=(k=i~j)Ak的求和
//给定N个整数序列{A1,A2,A3...An},求函数f(i,j)=(k=i~j)Ak的求和 # include<stdio.h> void main() { ,sum1; ]={,- ...
- 面试题:给定数组a,找到最大的j-i, 使a[j]>a[i]
第一种方法: 用两重循环对每对点都试一下,然后取最大值即可,时间复杂度为O(n2) #include <iostream> #include <algorithm> using ...
随机推荐
- c++11的记录
decltype()类型指示符 设定一个返回值是int的函数f(),通过使用 decltype(f()) sum = x; 此时decltype()接受一个从f()返回的int型的值,并将sum设置为 ...
- 杭电2019 数列有序!(STL解法)
由于这题对于学过数据结构的我来说,真的是很简单,为了减少时间上的损失,链表无疑是最好的选择(因为数组要往后移位子).然后,因为最近想玩些STL的骚操作,所以就用<list>了,然后顺便学了 ...
- cookie、session、localStorage、sessionStorage的区别
cookie的机制 cookie是存储在用户本地终端上的数据.有时也用cookies,指某些网站为了辨别用户身份,进行session跟踪而存储在本地终端上的数据,通常经过加密. Cookie是服务器发 ...
- SRSniffer抓包工具的使用
1.打开SRSniffer软件 2.按照1-->2-->3依次点击 3.点击左侧的启动监听按钮 4.打开要记录api的软件,查看效果
- 设计模式课程 设计模式精讲 8-2 单例设计模式-懒汉式及多线程Debug实战
1 主要内容 1.1 多线程debug 1.2 synchronized同步锁的调用 1.3 懒加载的应用 2 代码演练 2.1 单线程调用 2.2 多线程调用 2.3 锁的调用 1 主要内容 1.1 ...
- 揭秘autoit3的运行机制和反编译原理
今天发这个帖子的目的在于和论坛里面的朋友交流一下学习心得,主要内容是围绕着autoit3的编译原理.先开门见山的说一下结果,我不知道如何反编译au3,但相信论坛有很多高手,能解开我心中的疑团.我没有想 ...
- 【转载】如何快速转载CSDN中的博客
前言 对于喜欢逛CSDN的人来说,看别人的博客确实能够对自己有不小的提高,有时候看到特别好的博客想转载下载,但是不能一个字一个字的敲了,这时候我们就想快速转载别人的博客,把别人的博客移到自己的空间 ...
- 一探torch.nn究竟“What is torch.nn really?”
来自: https://pytorch.org/tutorials/beginner/nn_tutorial.html <What is torch.nn really?>这文章看起来不能 ...
- 用于云计算的自我更新、自我修补的Linux版本已发布!
自动化是 IT 行业的增长趋势,其目的是消除重复任务中的手动干扰.Oracle 通过推出 Oracle Autonomous Linux 向自动化世界迈出了又一步,这无疑将使 IoT 和云计算行业受益 ...
- 标准模板库中的向量(vector)
//C++数据结构与算法(第4版) Adam Drozdek 著 徐丹 吴伟敏<<清华大学出版社>> 头文件:#include<vector> 向量是最简单的S ...