#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
int t,n,m,i,sheng;
int x,y;
__int64 rong[100005];
__int64 a[100005];
cin>>t;
while(t--)
{
cin>>n>>m;
memset(a,0,sizeof(a));
for(i=1;i<=n;i++)
{
scanf("%I64d",&rong[i]);
}
while(m--)
{
cin>>x>>y; //x ping + y sheng
a[x]+=y;
}
for(i=1;i<=n;i++)
{
if(a[i]>rong[i])
{
a[i+1]=a[i+1]+a[i]-rong[i];
a[i]=rong[i];
}
}
cout<<a[n+1]<<endl;
for(i=1;i<=n-1;i++)
printf("%I64d ",a[i]);
printf("%I64d\n",a[n]);
}
return 0;
}
a[n+1]放多出的水很巧妙
倒水进i的时候,不用考虑i+1是否也溢出,即使i+1--n都溢出,可放入n+1
还有就是int64!!