Problems - Codeforces: Input Output
Problems - Codeforces: Input Output
Favorite numbers of Julia are numbers 3 and 7. She sympathizes with all output
numbers that are divisible by 3 or 7 (or even both of these numbers). 0
Thus, the beginning of the sequence of numbers, which Julia sympathizes
with, is: 3, 6, 7, 9, 12 , 14 , 15 , 18 , 21 , 24 ...
C. Unsorted Array
Find the k-th number among those whom Julia sympathizes with.
1 second, 256 megabytes
Input
The only line of the input contains an integer k (1 ≤ k ≤ 100). Peter does not like sorted arrays, so he asked you to build the permutation
of numbers 1, 2, … , n, such that there would be no segment of size k
Output that would be sorted (in ascending or descending order). Help him to find
Print the k-th positive integer number from the sequence of 3 and/or such permutation or tell that it is impossible.
7-divisible numbers.
A permutation of numbers 1, 2, … , n is an array of n elements such that
every integer from 1 to n appears in it exactly once.
input
2 Input
Input contains two integers n and k (2 ≤ k ≤ n ≤ 1000).
output
6
Output
Print the desired permutation, or −1 if it is not possible. If there are
multiple solutions, print any of them.
input
9
input
output 7 4
21
output
1 7 2 4 6 5 3
input
11
input
output 10 2
27
output
-1
B. Workstations
1 second, 256 megabytes input
4 3
To decide how many participants to invite to the final round of the
programming contest, the organizers first decided to see how many output
workstations they can assemble. After examining the equipment in the 4 1 3 2
warehouse, they found a desktop computers, b monitors, c all-in-one
computers, d keyboards and e mice. In order to assemble a single
workstation, you need one of the following sets:
D. Skis
2 seconds, 256 megabytes
desktop computer, monitor, keyboard, mouse
all-in-one computer, keyboard, mouse Skiing is very popular in Switzerland. The most popular ski resort has only
n skis, the size of the i -th ski is si . You think that skis are not divided into
Help the organizers find out how many workstations they can assemble. left and right and that two skis can be paired if the absolute difference of
Input their sizes does not exceed k. Formally, two skis i and j can be paired if
The input contains five integers a, b, c, d, e. All numbers are in range i ≠ j and |si − sj | ≤ k.
from 0 to 100, inclusive.
Your task is to compose the maximum number of ski pairs.
Output
Print the number of workstations. Input
≤ n ≤ 2 ⋅ 105 ,
The first line contains two numbers n and k (1
input 0 ≤ k ≤ 109 ) — the number of skis and the maximal difference of ski
sizes in a pair.
5 4 3 10 8
1 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...
input input
8 1 1 8
9 7 1 2 6 1 2 7 #..#...#
output output
3 A..B...C
4 6
8 2
7 3 input
5 7
##.....
input
##.###.
5 5 .......
5 4 3 2 1 .###.#.
.###...
output
output
2
5 3 AA.....
1 2 AA.BBB.
.......
.CCC.D.
input .CCC...
6 0
1 2 1 2 1 2
F. Zurich-Geneva
output
3 seconds, 256 megabytes
2
1 3
2 4 There are n people in the line at the ticket office of the train Zurich-
Geneva. There are m (m ≥ n) seats in the train, numbered from 1 to m.
input When the i -th person in the line is served at the ticket office, she/he asks
2 9 for a ticket to the seat ai . If this seat is open, the cashier sells a ticket to
11 1 this seat. If this seat is already taken, the cashier sells a ticket for the first
(minimum) open seat.
output
0 For each person in the line, find the number of the seat for which the ticket
will be sold to her/him.
input
3 4
input
##.. 11 11
##.. 3 1 4 1 5 9 2 6 5 3 5
...#
output
output
3 1 4 2 5 9 6 7 8 10 11
ZZ..
ZZ..
...W
G. Sum of Digits
1 second, 256 megabytes
2 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...
David loves books and math. Once, while reading an interesting book, he
output
came up with a mathematical problem. Consider the page numbers on the
3
page spreads of the book. The first spread contains page 1, the second
1 3 2 1 2
spread contains pages 2 and 3, the third spread contains pages 4 and 5,
etc. The task is to find the very first spread where the sum of the digits of
input
all page numbers is s. Try to solve this problem.
2 100
Input 1 2
The input contains a single number s from 1 to 300. output
Output 2
Print the page numbers that are on the desired page spread, in ascending 1 2
order. Print numbers without leading zeros. If there is no such spread, print
- 1. I. Roads
input 3 seconds, 256 megabytes
Input
input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 105 ). The second
3
line contains n integers d1 , d2 , … dn (0 ≤ di ≤ n − 1).
output
Output
10 11 In solution exits, in the first line print YES. Print NO in the opposite case. In
case of positive answer print n − 1 lines containing pairs of integers xj ,
yj (1 ≤ xj , yj ≤ n ), meaning that the j-th road goes from the city xj to
H. Wireless Access Points
the city yj . If there are multiple answers, print any.
3 seconds, 256 megabytes
input
There are n wireless access points in the long straight corridor: the i -th of
them are located at a distance xi along the corridor from the entrance to 8
3 2 2 0 1 2 1 2
the building.
output
It is known that if two wireless access points are installed at a distance of
less than d, then they must work at different frequencies. What is the least YES
4 5
number of frequencies needed to set up all the points? Find a way to 4 7
assign frequencies so that any two points at distance less than d have 5 2
different frequencies, and the total number of different frequencies used is 5 3
minimal. 7 6
7 8
Input 2 1
The first line of the input contains two positive integers n and d
(1 ≤ n ≤ 2 ⋅ 105 , 1 ≤ d ≤ 109). input
5
The second line contains a sequence of distinct integers x1 , x2 , … , xn
4 3 2 1 0
(1 ≤ xi ≤ 109 ). No two wireless access points are located at the same
point. output
YES
Output 5 4
In the first line print k — the minimal number of frequencies. Print in the 4 3
second line integer frequencies d1 , d2 , … , dn (1 ≤ di ≤ k), where di is 3 2
2 1
the frequency for the i -th wireless access point.
3 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...
input input
5 6 3
1 2 3 4 4 4 2
5 7
output 3 6
4 10
NO
7 1
3 8
The mayor of Bytesburg decided to check the condition of the roads after In this example there are 6 orders, and we need to fulfill 3 of them.
reconstruction. To do this, he wants to drive along each road in both
If we choose orders 6, 3, and 1, the maximal time the customer receives
directions.
their order will be 12:
Help the mayor to find the shortest route that goes along each road in
Order 6 will be cooked in time 3, and it will be delivered to the customer in
each direction at least once.
time 11 (3 + 8).
Input
Order 3 will be cooked in time 6 (3 + 3), and it will be delivered to the
There are n intersections and m roads, each road connects two different
customer in time 12 (6 + 6).
intersections. There can be no more than one road between two
intersections. Order 1 will be cooked in time 10 (6 + 4), and it will be delivered to the
customer in time 12 (10 + 2).
It is guaranteed that you can reach each intersection using the roads.
output Initially, Mia is in the upper left cell and looks in the direction to the right.
She needs to complete her journey in the same (upper left) cell and look in
6
1 3 2 1 2 3 1 the same direction (to the right). Thus, the route is a cyclic string of letters
L, R and F.
K. Delivering Problem Mia does not like regular patterns, so she wants her route to be irregular.
As a criterion for irregularity, Mia proposed the following. She considers
2 seconds, 256 megabytes the route irregular if there are no two substrings of length
−−−−−−−−−
You work in a small cafe. Today the cafe received n orders for delivery.
[20√max (n, m)] that are equal. In other words, there should not be
two such different positions in the cyclic string corresponding to the route,
For each order you know two numbers: ti is the time needed to cook the −−−−−−−−−
order, and di is the time needed to deliver the order to the customer. that sequences of length [20√max (n, m)] starting at these positions
There are more than n couriers in the cafe, so all deliveries may be done coincide. The brackets in the restriction indicate rounding down.
in parallel, but there is only one kitchen, so the orders can only be cooked Help Mia to find any irregular route.
only one by one.
Input
The cafe can fulfill exactly k orders from the given n, your task is to select Input contains two integers n and m (4 ≤ n, m ≤ 400), size of the field.
the orders and the order they should be cooked, in such a way, that the Both numbers are even.
maximal time the customer receives their order is minimal possible.
Output
Input Print the irregular route as a string of letters L, R and F. The route should
First line contains two integers n and k (1 ≤ k ≤ n ≤ 2000). Next n go through each cell exactly once, it should start from the upper left cell
lines contain pairs of integers ti and di (1 ≤ ti , di ≤ 105 ). facing to the right and end in the same cell in the same position.
Output If there are multiple answers — print any of them.
Print k integers: the numbers of orders you want to fulfill, in the order they
should be cooked. If there are multiple optimal answers, print any of them. input
4 4
output
FFFRFFFRFFFRFRFFLFLFFRFR
4 of 5 17/06/20, 1:42 pm
Problems - Codeforces https://sitstar.contest.codeforces.com/group/v...
5 of 5 17/06/20, 1:42 pm