0% found this document useful (0 votes)
54 views

ocpc

bla bla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

ocpc

bla bla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1

A. Open the Lock


Time limit per test : 2 seconds
Memory limit per test : 256 megabytes per test
Ballon color : yellow

You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots:
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The wheels can rotate freely and wrap around:
for example we can turn '9' to be '0', or '0' to be '9'. Each move consists of turning
one wheel one slot.

The lock initially starts at '0000', a string representing the state of the 4 wheels.

You are given a list of deadends, meaning if the lock displays any of these codes,
the wheels of the lock will stop turning and you will be unable to open it.

Given a target representing the value of the wheels that will unlock the lock,
return the minimum total number of turns required to open the lock, or -1 if it is
impossible.

Input
The first line contains a single integer N (1 ≤ N ≤ 500) —the number of
deadends.

The second line contains an N string separated by a single space, each one with
length 4 consists of digits only representing a deadends.

Third line contains a single string S with length 4 consists of digits only represent
the target
Output
2

Print in a single line the minimum total number of turns required to open the lock,
or -1 if it is impossible.
Example

Standard input Standard output


1 1
8888
0009

8 -1
8887 8889 8878 8898 8788 8988 7888 9888
8888

5 6
0201 0101 0102 1212 2002
0202
3

B. Shaass and Oskols


Time limit per test : 2 seconds
Memory limit per test : 256 megabytes
Ballon color : white

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
4

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

Standard input Standard output


5 0
10 10 10 10 10 12
5 5
0
2 5 16
3 13
2 12
1 13
4 6

3 3
241 0
1 3
22
5

A. Kuriyama Mirai's Stones


Time limit per test : 2 seconds
Memory limit per test : 256 megabytes per test
Ballon color : yellow

Kuriyama Mirai has killed many monsters and got many (namely n) stones. She
numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai
wants to know something about these stones so she will ask you two kinds of
questions:

1. She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her
𝑟
∑ 𝑣𝑖 .
𝑖=𝑙

2. Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th
place if we arrange all the stone costs in non-decreasing order). This time
she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her
𝑟
∑ 𝑢𝑖
𝑖=𝑙

For every question you should give the correct answer, or Kuriyama Mirai will say
"fuyukai desu" and then become unhappy.

Input

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n
integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama


Mirai's questions. Then follow m lines, each line contains three integers type, l
6

and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you


should output the answer for the first question, else you should output the answer
for the second one.

Output

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's
question. Print the answers to the questions in the order of input.

Examples

Standard input Standard input


6 24
642727 9
3 28
236
134
116

4 10
5523 15
10 5
124 15
214 5
111 5
214 2
212 12
111 3
133 5
113
144
122
7

You might also like