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 ...
随机推荐
- FCN训练注意事项
1.如果是类别受两类,需要把标签图二值化为0,1
- MessageBox函数
<Windows程序设计>(第五版)(美Charles Petzold著) https://docs.microsoft.com/zh-cn/windows/desktop/apiinde ...
- Java后端 带File文件及其它参数的Post请求
http://www.roak.com Java 带File文件及其它参数的Post请求 对于文件上传,客户端通常就是页面,在前端web页面里实现上传文件不是什么难事,写个form,加上enctype ...
- Springboot + redis + 注解 + 拦截器来实现接口幂等性校验
Springboot + redis + 注解 + 拦截器来实现接口幂等性校验 1. SpringBoot 整合篇 2. 手写一套迷你版HTTP服务器 3. 记住:永远不要在MySQL中使用UTF ...
- 【项目】小试牛刀-polo360静态网页项目(附psd文件资源)
笔者尝试下开发简单的静态网页,下面分享过程及源码.这是polo360的下载链接:https://pan.baidu.com/s/1WqGxKMYY_DHfrSJ9lLL-WA 提取码:v2qi (一 ...
- How to add VTL tapes on DD6300 & label them into "Oracle_VTL" pool
Dear all , This is liulei , I was back so , How to add VTL tapes on DD6300 & label them into ...
- PHP开发者该知道的5个Composer小技巧
Composer 是新一代的PHP依赖管理工具.本文介绍使用Composer的五个小技巧,希望能给你的PHP开发带来方便. 1. 仅更新单个库 只想更新某个特定的库,不想更新它的所有依赖,很简单 co ...
- System.Diagnostics.Conditional 的妙用 -- 把文档放在代码中
最近的工作跟 UI 打交道比较多, 各种坑. 今天从 Prefab 的序列化功能来说说 System.Diagnostics.Conditional 的妙用. 我们做 UI 面对各种按钮, 组件的获取 ...
- Kubernetes 的一些重要概念
Cluster Cluseter 是计算.存储和网络资源的集合,Kubernetes 利用这些资源运行各种基于容器的应用. Master Master 是 Cluster 的大脑, 它的主要责任是调度 ...
- 四 SpringMVC与页面之间的参数传递&高级参数的绑定&日期类型的转换
参数传递: 1 原生方式:使用Servlet API , request.getParameter("id"); 2 直接将请求参数作为Controller中的形参: publ ...