Processing algorithms


Plus
Pin


Problem description Progress
ID 38716. Gromozeka's Joy
Темы: Arrays    Processing algorithms   

Gromozek has a sequence of integers A of length N. It will make three slices in the  A sequence and split it into four (non-empty) contiguous subsequences B, C, D > and E. He chooses the positions of the slices arbitrarily. Let P, Q, R, S be the sums of elements in B, < code>C, D,  E respectively. Gromozeka will be happy when the absolute difference between the maximum and minimum between P, Q, R, S  minimum. Find the smallest possible absolute difference between the maximum and minimum between P, Q, R, S.

Input
The first line contains an integer N  (\(1<=N<=2 \cdot 10^5\)). The second line contains N integers Ai (\(1<=A_i<=10 ^9\)).

Imprint
Print the smallest possible absolute difference between the maximum and minimum between P, Q, R, S.
 

Examples
# Input Output Explanations
1 5
3 2 4 1 2
2 If we divide A by B, C, D, E = (3), (2), (4), (1,2), then P = 3, Q = 2, R = 4, S = 1 + 2 = 3.
Here the maximum and minimum among P, Q, R, S are 4 and 2, with an absolute difference of 2.
We can't make the absolute difference between the maximum and minimum less than 2, so the answer is 2.
2 10
10 71 84 33 6 47 23 25 52 64
36  
3 7
1 2 3 1000000000 4 5 6
999999994  

ID 39382. Will you solve it?
Темы: One-Dimensional Arrays    Processing algorithms   

There are N parts of some source code. The characteristics of the ith part of the code are represented by M integers Ai1, Ai2< /sub>, ..., AiM . You are given integers B1, B2, ...< /font>, BM , and C.
The ith part of the code solves the problem correctly if and only if \( A_{i1}\cdot B_1 + A_{i2} \cdot B_2 + ...+ A_{iM}\cdot B_M +C>0\).
Among the N parts of the source code, find the number that correctly solve this problem.

Input
The first line contains three space-separated numbers: N, M (1 <= N, M <= 20) and C (- 100 <= C <= 100). The second line contains   M numbers Bi (-100 <= B<= 100). Each of the following N lines contains numbers Ai (-100 <= A ij <= 100, 1 <= i <= N, 1 <= j <= M).

Imprint
Print one number - the answer to the problem.
 

Examples
# Input Output
1 2 3 -10
1 2 3
3 2 1
1 2 2
1
2 5 2 -4
-2 5
100 41
100 40
-3 0
-6 -2
18-13
2
3 3 3 0
100 -100 0
0 100 100
100 100 100
-100 100 100
0

ID 29448. Rose of Wind
Темы: One-Dimensional Arrays    Processing algorithms   

When choosing a construction site for a residential complex at a metallurgical plant, it is necessary to take into account the "wind rose"; (the residential complex should be located so that the frequency of the wind from the side of the metallurgical plant would be minimal). To do this, during the year, the wind direction was recorded in the construction area. The data is presented as an array in which the wind direction of the wind for each day (365) is encoded as follows: 
1 - northern (N),
2 - southern (S)
3 - east (E)
4 - western (W)
5 - northwest (NW)
6 - northeast (NE)
7 - southwest (SW)
8 - southeast (SE).
Determine how the residential complex should be located in relation to the plant

Input: 
The first line contains 365 values ​​from 1 to 8 (wind direction)

Imprint:
Print the corresponding letters (abbreviation - see the list above) on which side the residential complex should be built
 

ID 37169. Game "Life". Easy option
Темы: 2D arrays    Processing algorithms   

In some cells of the square \( N\ х\ N\) microorganisms live (no more than one in one cell). The following happens every second:
– all microorganisms that have less than 2 neighbors die of boredom (neighbors are microorganisms that live in cells that have a common side or top);
– all microorganisms with more than 3 neighbors die from overcrowding;
– on all empty cells, in which microorganisms lived in exactly three adjacent cells, new microorganisms appear.
All changes occur simultaneously, that is, for each cell, its fate is first clarified, and then changes occur in all cells at once.
It is required to determine from this configuration what it will turn into after \(T\) seconds.

Input data: The first line contains two natural numbers –\( N\) (\(1 \leq N \leq 10\)) and \(T\) (\(1 \leq T \leq 100\)). Next,  \( N\) lines of \( N\) numbers, describing the initial configuration (0 – empty cell, 1 – microorganism). Numbers in lines are separated by spaces.
Output: Required to output \( N\) lines by \( N\) numbers – a description of the configuration in T seconds (in the same format as in the input data).

Examples
# Input Output
1 3 1
1 0 1
1 0 1
1 0 1
0 0 0
1 0 1
0 0 0
2 2 2
1 1
1 1
1 1
1 1
3 5 10
1 0 1 1 0
0 1 0 0 0
0 0 0 1 0
0 0 0 0 0
0 1 0 1 0
0 1 1 0 0
0 1 1 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

ID 42268. Hidden map
Темы: One-Dimensional Arrays    Processing algorithms   

In the deck, Gromozeka has cards on which one whole number is written. Each number in the deck occurs exactly 4 times. 
Thus, in the deck there are 4 cards with the number 1, 4 cards with the number 2, ..., 4 cards with the number N. In total, there are 4*N cards in the code.

Gromozeka shuffled those cards, then hid one of them and gave you a stack of the remaining 4*N-1 cards. The i-th card (1<= i <=4*N−1) from the stack contains an integer Ai.

Find the integer written on the card that Gromozeka hid.

Input
The program receives two lines as input. The first line contains the integer N (1 <= N <= 105).  The second line contains 4*N-1 integers Ai (1 <= Ai <= 4*N−1. 1<= i <=4*N−1). For each (1<=k<=N) there are at most 4 i indices, such that Ai=k.


Imprint
Print the answer to the problem.
 
 

Examples
# Input Output
1 3
1 3 2 3 3 2 2 1 1 1 2
3
2 1
1 1 1
1
3 4
3 2 1 1 2 4 4 4 4 3 1 3 2 1 3
2

ID 42271. Number of elements greater than both neighbors
Темы: One-Dimensional Arrays    Processing algorithms   

You are given an array of integers. Write a program that in the given array determines the number of elements that have two neighboring elements and, at the same time, both neighboring elements are less than the given one.


Input

First given is a number N - number of elements in the array (1 <= N <= 10000). Then, space-separated  N numbers - elements of the array. The array consists of integers.


Output

You need to output the number of array elements that have two neighbors and are strictly greater than both of their neighbors.

 
Examples
# Input Output
1
5
1 2 3 4 5
0
2
5
2 3 2 4 3
2

ID 42324. Find and count
Темы: Arrays    Processing algorithms   

Given two integer sequences, each of length NA = (A1, A 2, ..., AN) and B = (B1, B2, ..., BN).
All A elements are different. All B elements are also different.

Print the following two values.

  1. The number of integers contained in both and B appearing in the same position in the two sequences. In other words, the number of integers  i numbers such that A= Bi.
  2. The number of integers contained in both and B that appear at different positions in the two sequences. In other words, the number of pairs of integers  (i, j) numbers such that A= Band i ≠ j.


Input
The program receives three lines as input. The first line contains one number N (1 <= N <= 1000) - the number of numbers in the sequence. The second line contains numbers A1, A2, ..., AN, all numbers are different . The third line contains numbers B1, B2, ..., B, all numbers various (1 <= Ai, Bi <= 109). 

Imprint
Print the answer to the first question on the first line, and the answer to the second on the second line.
 
 
Examples
# Input Output
1
4
1 3 5 2
2 3 1 4
1
2
2
3
1 2 3
4 5 6
0
0