CodeForces - 294A Shaass and Oskols

Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass‘s territory. Supposed there are ai oskols sitting on the i-th wire.

Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the i-th wire). Consequently all the birds on the i-th wire to the left of the dead bird get scared and jump up on the wire number i?-?1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number i?+?1, if there exists no such wire they fly away.

Shaass has shot m birds. You‘re given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.

Input

The first line of the input contains an integer n, (1?≤?n?≤?100). The next line contains a list of space-separated integers a1,?a2,?...,?an,(0?≤?ai?≤?100).

The third line contains an integer m, (0?≤?m?≤?100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass shoot the yi-th (from left) bird on the xi-th wire, (1?≤?xi?≤?n,?1?≤?yi). It‘s guaranteed there will be at least yi birds on the xi-th wire at that moment.

Output

On the i-th line of the output print the number of birds on the i-th wire.

Examples

input

510 10 10 10 1052 53 132 121 134 6

output

0125016

input

32 4 112 2

output

303

题意:有个人闲着无聊去打电线上的绿鸭子,而他在打死一只蠢鸭子后,那只鸭子前面的鸭子向左的电线杆上飞,后面的向右飞,如果没了电线杆,它们就飞走了。最后问你每根电线杆上有几只鸭子。

题解:不必多说,模拟即可

代码:

var
  a:array[1..200] of longint;
  n,m,x,y,i,j,k:longint;
begin
  readln(n);
  for i:=1 to n do
  read(a[i]);
  readln(m);
  for i:=1 to m do
  begin
    readln(x,y);
    if x>1 then a[x-1]:=a[x-1]+y-1;
    if x<n then a[x+1]:=a[x+1]+a[x] -y;
    a[x]:=0;
  end;
  for i:=1 to n do
  writeln(a[i]);
end.
时间: 2024-12-21 21:57:10

CodeForces - 294A Shaass and Oskols的相关文章

codeforces A. Shaass and Oskols 题解

Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delici

Codeforces 294B Shaass and Bookshelf(记忆化搜索)

题目 记忆化搜索(深搜+记录状态) 感谢JLGG //记忆话搜索 //一本书2中状态,竖着放或者横着放 //初始先都竖着放,然后从左边往右边扫 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int dp[110][210][210];//dp[第几个][厚度][宽度] int n; int a[110],b[110]; int rec(int i,int th,

Codeforces 294B Shaass and Bookshelf:dp

题目链接:http://codeforces.com/problemset/problem/294/B 题意: 有n本书,每本书的厚度为t[i],宽度为w[i] (1<=t[i]<=2, 1<=w[i]<=100). 然后让你将所有书按照下面的方式摆放: 在下面放一本书会占用下面t[i]的长度. 在上面放一本书会占用上面w[i]的长度. 最终要保证上面的总长度不超过下面的总长度. 问你下面的总长度最小是多少. 题解: 表示状态: dp[i][j] = min length 表示已经

CodeForces 294B Shaass and Bookshelf 【规律 &amp; 模拟】或【Dp】

这道题目的意思就是排两排书,下面这排只能竖着放,上面这排可以平着放,使得宽度最小 根据题意可以得出一个结论,放上这排书的Width 肯定会遵照从小到大的顺序放上去的 Because the total thickness of vertical books is fixed it's good to calculate the minimum possible total width of horizontal books. 那么只需要模拟一遍放书的过程即可,不会TLE 不过正统解法是Dp Dp

codeforces 294B Shaass and Bookshelf

题意:给你n本书,你可以把它竖着摆放,然后也可以横着摆在竖着的书上面,但不能超过竖着摆放的边缘,且不可以堆叠.问你竖着摆放的最小宽度是多少. 解题思路:dp,dp[i][j] 代表 第i个 ,用竖着摆放为 j 的书横着摆放的最小值 解题代码: 1 /************************************************************ 2 * Author : darkdream 3 * Email : [email protected] 4 * Last mo

Codeforces 294E Shaass the Great 树形dp(水

题目链接:点击打开链接 题意: 给定n个点的树,任意拆掉一条边,得到2个子树,再用刚拆掉的边把这两个子树连起来. 得到新的树,这个树的权值为任意两个点间的距离和. 使得新的树权值最小.输出这个权值. 枚举拆掉的边(u,v) 得到2个以u为根的子树和以v为根的子树 计算每条边对答案的贡献,拆掉的边贡献就是siz[u]*siz[v]*edge[u,v].dis 剩下的就是计算如何连接2个子树使得权值和最小. 对于子树中的一条边x, y,若已知两端的节点数为i,j,则这条边对答案的贡献就是 i*j*e

Codeforces Round #178 (Div. 2) B .Shaass and Bookshelf

Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensions to be as small as possible. The thickness of the i-th book is ti and its pages' width is equal to wi. The thickness of each book is either 1 or 2.

#Shaass and Lights:CodeForces - 294C

1 /******************************************************************************************************************************************************************************* 2 题目大意:给出一列灯,初始有一些点亮的灯,每次只能点亮与已经点亮的灯相邻的灯,问点亮所有灯的方案有多少种 3 题解: 4 首先利用初始已经

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多