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

DIU Unlock the Algorithm Programming Contest Fall-24 [Preliminary - B Slot]

The DIU Unlock the Algorithm Programming Contest Fall-24 is a 3-hour programming contest featuring 8 challenges, adhering to ICPC rules. Participants can use various programming languages, and plagiarism will lead to disqualification. The document outlines specific problems related to programming tasks and their input/output requirements.

Uploaded by

shahriarmonon
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)
17 views

DIU Unlock the Algorithm Programming Contest Fall-24 [Preliminary - B Slot]

The DIU Unlock the Algorithm Programming Contest Fall-24 is a 3-hour programming contest featuring 8 challenges, adhering to ICPC rules. Participants can use various programming languages, and plagiarism will lead to disqualification. The document outlines specific problems related to programming tasks and their input/output requirements.

Uploaded by

shahriarmonon
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/ 15

DIU Unlock the Algorithm

Programming Contest Fall-24


[Preliminary - B Slot]

https://toph.co/c/diu-unlock-the-algorithm-fall-24-preliminary-b
Schedule
The contest will run for 3h0m0s.

Authors
The authors of this contest are diuacm, iffatul_anon, and kazi_amir.

Rules
This contest is formatted as per the official rules of ICPC Regional Programming
Contests.

You can use Bash 5.2, Brainf*ck, C# Mono 6.0, C++17 GCC 13.2, C++20 Clang 16.0, C+
+20 GCC 13.2, C++23 GCC 13.2, C11 GCC 13.2, C17 GCC 13.2, C23 GCC 13.2, Common
Lisp SBCL 2.0, D8 11.8, Erlang 22.3, Free Pascal 3.0, Go 1.22, Grep 3.7, Haskell 8.6, Java
1.8, Kotlin 1.9, Kotlin 2.0, Lua 5.4, Node.js 10.16, Perl 5.30, PHP 8.3, PyPy 7.3 (3.10),
Python 3.12, Ruby 3.2, Rust 1.57, Swift 5.3, and Whitespace in this contest.

Be fair, be honest. Plagiarism will result in disqualification. Judges’ decisions will be


final.

Notes
There are 8 challenges in this contest.

Please make sure this booklet contains all of the pages.

If you find any discrepencies between the printed copy and the problem statements in
Toph Arena, please rely on the later.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 2 of 15


A. Kiyan, The Coder
In 20052005
2005, in a small village, Kiyan was born. His father, Mr. Levin, cradled him and
declared with pride, “This boy will be a programmer!” The words weren’t just a wish—
they became a mission.

By 20112011
2011, six-year-old Kiyan was in primary school, but it wasn’t books that fascinated
him; it was the old, clunky computer his father had bought with hard-earned money.
Kiyan spent hours exploring its secrets, his small fingers dancing across the keyboard.
In 20162016
2016, after finishing primary school, Kiyan joined a programming academy. While his
peers struggled with code, Kiyan treated algorithms like puzzles, cracking them
effortlessly. His teachers called him a prodigy.

By 20222022
2022, Kiyan was admitted to Daffodil International University. There, he joined the
prestigious DIU-ACM community, diving into the high-pressure world of competitive
programming. Now, in20242024
2024, Kiyan is not just a programmer—he’s a rising star
representing DIU-ACM. He is just Insane.

Now, your task is to print the specific year in which Kiyan joined the programming
academy.

Input
There is no input in this problem.

Output
Print the year in which Kiyan joined the programming academy.

Be careful about the newline(‘\n’) at the end.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 3 of 15


B. The Treasure Hunt Puzzle (Hard)
During an intense ICPC (International Collegiate Programming Contest) practice
session, your team finds an intriguing riddle embedded in the problem set. The
problem hints at a treasure hunt on a mysterious map represented by an array A. Each
element in the array corresponds to a location ID, and one of these locations holds the
key to the treasure. However, the treasure is not in the first occurrence of a location;
k−thk-
instead, you must find the k − th occurrence of a specific location x.
th
The riddle comes with a dire warning: "If the treasure is hidden beyond the k-th
occurrence, it is lost forever!"

Your team quickly realizes that solving this puzzle efficiently is crucial to uncover the
treasure and secure the top spot in the competition. Can you determine whether the
k−thk-
k − th occurrence of the location exists in the map? If it does, can you find its
th
position? −1-1a −1, signaling that the
If it doesn’t, the team must report back with
treasure hunt ends in failure.

The stakes are high, and time is running out. The team turns to you, the programming
wizard, to crack the puzzle. Will you rise to the challenge?

Input
1. The first line contains an integer nn
n — the number of elements in the array.
2. The second line contains
nnn integers — the elements of the AA A[i]A[i]A[i]
array A(
represents the ID of the ii−thi-
− th location).
th
3. The third line contains two integersxx
x (the location ID) andkk
k (the occurrence to
find).

Output
Print a single integer:

• The 1
1−basedindex1-
− based
based\
index k−thk-
of the k − th occurrence of x, or
\ th
• −1-1
−1 ifindex k−thk-
the k − th occurrence does not exist.
th

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 4 of 15


Samples
Input Output
10 2
4 2 6 4 8 3 9 4 2 6
2 1

Constraints:

11≤n≤5001
≤ n ≤ 500
≤ ≤ A[i], x ≤ 103
11≤A[i],x≤1031
n
≤≤ k ≤ 103
11≤k≤1031
A[i],x

500

k≤
10^3

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 5 of 15


C. The Pair Matching
Your ICPC team is in a heated coding competition, where one of the problems involves
testing your analytical and programming skills to the limit. The challenge revolves
around an array of integers representing scores from a recent practice session.

The problem requires identifying whether there exists a pair of scores such that their
product is divisible by a given numberKK
K . This means you must determine if there are
any two elements A[i]A[i]
A[i] and A[j]A[j] i=
 j in the array such that:
A[j] where i≠ji≠j
(A[i]×A[j])%K=0(A[i]
(A[i] × A[j]) % K = 0
×
Your
A[j])team must decide quickly to either celebrate a successful "pair match" or accept
that no such pair exists.
\hspace{0.1cm}
\
Input
%
\hspace{0.1cm}
K 1. The first line contains two integers N and K, where:
=
◦ N is the number of scores in the array.
0
◦ K is the divisor to check the product against.

◦2
2≤N≤2 103 , 11≤K≤1
≤ N ≤ 10310^3 109
≤ K ≤ 10910^9
\le \le
2. The second line contains N space-separated integers, the scores in the array A,
N K
where:\le \le
◦0
0≤A[i]≤0 105 .
≤ A[i] ≤10510^5
≤A[i]≤
Output
1. Print YES if there exists at least one pair of indices(i,j)
(i, j), wherei≠ji\neq
i=
 j such that
(A[i]×A[j])%K=0(A[i]
(A[i] × A[j]) % K = 0 (i, j
× j)
2. Otherwise, print NO.
A[j])
\hspace{0.1cm}
Samples
\
%
Input\hspace{0.1cm} Output
5 2 K YES
1 2 3=4 5
0

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 6 of 15


Input Output

Explanation:

In the first case, if we take index ii


i = 1 and jj
j = 2, then
(A[i]×A[j])%K(A[i]
(A[i] × A[j]) % K
×
= (1 x 2) % 2
A[j])
\hspace{0.1cm}
=2%2
\
%0
=
\hspace{0.1cm}
So there exist a pair.
K

Input Output
2 10 YES
10 10

Input Output
2 9 NO
2 3

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 7 of 15


D. The Wallet of Infinite Powers
In Alex’s country, the currency consists only of coins with values1,1, 2, 4, 8, 16, 32, …
like this sequence. 2,
4,
8, nnn coins, and he
Alex went to a supershop to buy some groceries. His wallet contains
needs exactly kkk Tk to pay for his groceries. He wants to use the16,
minimum number of
coins to make the payment. 32,…
1,
However, Alex does not want to spend extra money. If he cannot pay exactly kkk Tk, he
2,
will not buy anything.
4,
8,16,
Input 32,
The first line contains two integers,n(1≤n≤105)n k(1 ≤ …k ≤ 1015 ), wherenn
n(1 ≤ n ≤ 105 ) andk(1≤k≤1015)k n
(1 wallet, and kk
represents the number of coins in the k is the (1
total cost.
≤ ≤
15
The second line contains nn
n integersnc1,c2,...,cn(1≤ci≤1015)
c1 , c2 , ..., cn (1 ≤ ci ≤
k 10 ) where cicᵢ
ci represents
c₁,
the value of the coins. The values≤are given in ascending
≤ order, and there may be
duplicate coins in the wallet. c₂,...,
10^5) 10¹⁵)
cₙ
(1
Output

kkk Tk,
Print the minimum number of coinscᵢrequired. If it is not possible to give exactly
print −1-1
−1. ≤
10¹⁵)
Samples
Input Output
5 24 2
1 2 4 8 16

Input Output
5 32 -1
1 2 4 8 16

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 8 of 15


E. The Enchanted Scroll of the Lost
Kingdom
Long ago, in the heart of a mysterious and forgotten kingdom, a group of ancient
scholars uncovered an enchanted scroll. This scroll, said to be blessed by the gods,
holds the key to finding the lost treasure of the kingdom — a treasure so vast that it
could alter the course of history.

The scroll is filled with magical numbers, arranged in a sorted sequence and each one
representing an essential clue to the treasure’s location. However, the scroll is not a
simple map. The numbers repeat in patterns, and the key to unlocking the treasure lies
in finding the first and last appearance of certain numbers within the array. Only by
knowing where each number occurs can the adventurers proceed to the next clue.

As an adventurer entrusted with this critical task, you must assist your team by
uncovering the distance between the first and last appearances of the numbers. Your
goal is to help the team navigate through the scroll’s many mysteries and bring them
closer to the treasure. But beware, time is running out, and the secrets of the kingdom
may soon be lost forever.

Input
The first line contains two integersNN Q (1 ≤ N , Q ≤ 105 ) — the size of the
N andQ(1≤N,Q≤105)Q\hspace{0.2cm}
array AA (1
A and the number of queries, respectively.
\le
The second line containsNN
N integers representing
N, A(1≤A[i]≤109)A\hspace{0.2c
the sorted array A (1 ≤ A[i] ≤
109 ) (the enchanted scroll). Q (1
\le \le
The next QQ X (1 ≤ X ≤ 109 ) — a A[i]
Q lines each contain an integer X(1≤X≤109)X\hspace{0.2cm}magical number for
10^5)
which the distance between the first and (1
last occurrence must be calculated.
\le
\le 10^9)
X
Output
\le
For each query, output a single integer: 10^9)

• If the number XX
X appears in the array, print the distance between the index of its
last and first occurrence.

• If the number XX
X does not appear in the array, print −1-1
−1, signaling that the clue is
no longer relevant.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 9 of 15


Samples
Input Output
10 3 2
1 2 3 3 3 4 4 5 6 7 1
3 0
4
5

Be careful about the newline(‘\n’) at the end.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 10 of 15


F. Billu needs help
Billu is good at mathematics, so most of the time he gets the highest marks in weekly
exams. Sometimes he doesn’t get the highest marks because of his friend SidhaSakib.
SidhaSakib is also good at mathematics, so there is always a battle between Billu and
SidhaSakib. Billu feels sad when he gets lower marks than SidhaSakib. Billu’s parents
are very strict, they always want Billu to improve in mathematics, so they judge his
mathematical ability with his weekly exam mark. After so many weekly exams his
parent want to see his weekly exam marks, but Billu doesn’t want to show all his
weekly exam marks because he got lower marks in some weekly exams. His parents
will be happy If his current mark is strictly greater than the previous ones. So Billu
wants to maximize his weekly exam marks. As you are Billu’s best friend now he wants
your help finding the minimum number of weekly exam marks he can remove so that
his parents will be happy after seeing his result sheet.

You are given an array a of size n, where every element of the array a[i] represents
Billu’s i-th weekly exam marks.

Input
The first line will be a single integer N indicating the number of weekly exams. The
following N lines will contain an Integer a[i] which represents the number of i-th
weekly exams.

Constraints:

≤ N ≤ 105
11≤N≤1051\le
≤ A[i] ≤ 106
N\le10^5
11≤A[i]≤1061\le
A[i]
\le10^6
Output
You have to print a integerKK
K , the minimum number of exam marks he must remove
so that his parents will be happy.

Samples
Input Output
4 1
1 2 3 1

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 11 of 15


In this example: Billu can arrange at most 3 weekly exam marks according to his
parents happiness.
numbers are: [1,2,3], he cannot add the last element.

he must remove the last element, so the answer is 1.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 12 of 15


G. HoneyTrap
You find yourself on an island where a treasure hunt is in progress, and you’ve been
given a magical array of integers! The game begins with an array of size n, and all the
elements of the array are set to11
1. However, you have the power to perform a magical
operation that allows you to increase the value of an array element.

Here’s how it works: for each elementa[i]a[i]


a[i] in the array, you can select it and a positive
integer xx
x, and you can increase its value by the integer part ofa[i]/
a[i]/x (i.e. you replace
a[i]=a[i]
a[i] xa[i] / up to kk
= a[i] + ⌊a[i]/x⌋). You are allowed to perform these operations k times.
+ x
There
⌊a[i]/ are specific treasure values hidden at various points on the island, and each
treasure
x⌋ is guarded by a magical lock. Each lock corresponds to a specific value b[i]b[i]
b[i],
a[i] you must match the value ofa[i]a[i]
and b[i]b[i]
a[i] with b[i] in order to unlock it. Once unlocked,
= receive a number of coins c[i]c[i]
you c[i] for every match.
a[i]
Your goal is to maximize the number of coins you can gather by performing no more
+
than kk
k operations. Every time you perform an operation; you change the value of an
⌊ a[i] /
element in the array and try to match it to one of the treasures on the island. You want
x⌋
to be strategic in your choices to ensure you gather as many coins as possible.

Rules

• nn
n is the size of the array.
• You can perform at most kk
k operations on the array.
• For each a[i]a[i]
a[i] that matches b[i]b[i]
b[i] after the operations, you receive c[i]c[i]
c[i] coins.

Input
The first line contains a single integer t(1≤t≤100)t
t(1 ≤ t ≤ 100) — the number of test cases.
For each test case: (1

• The first line contains two integers:
t n(1 ≤ n ≤ 103 )
n(1≤n≤103)n
the size of the array:
and the maximum number of operations:
≤ k(0 ≤ k ≤ 106 )(1
k(0≤k≤106)k .
100) (0 ≤
• The second line contains n integers representing the target valuesb(1≤b[i]≤103)b
b(1 ≤
≤ n
3 (1
b[i] ≤ 10 ). k ≤

• The third line contains n integers representing 10^3) ≤
c(1≤c[i]≤106)c
b[i]c(1 ≤
the number of coin
6 10^6) (1
c[i] ≤ 10 ) you will earn for each match.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 13 of 15


The sum of nn 104 .
n over all test cases does not exceed 10410^4 c[i]


10^3)
10^6)
Output
For each test case, print one integer — the maximum number of coins that you can
get by performing no more than kk
k operations.

Samples
Input Output
4 9
4 4 0
1 7 5 2 30
2 6 5 2 167
3 0
3 5 2
5 4 7
5 9
5 2 5 6 3
5 9 1 9 7
6 14
11 4 6 2 8 16
43 45 9 41 15 38

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 14 of 15


H. The Treasure Hunt Puzzle (Easy)
During an intense ICPC (International Collegiate Programming Contest) practice
session, your team finds an intriguing riddle embedded in the problem set. The
AA
problem hints at a treasure hunt on a mysterious map represented by an array A.
Each element in the array corresponds to a location that holds the key to the treasure.

The riddle comes with a dire warning: "If the treasure is hidden beyond the occurrence, it
is lost forever!"

Your team quickly realizes that solving this puzzle efficiently is crucial to uncover the
treasure and secure the top spot in the competition. Can you determine whether the
number XX
X exists in the map? If it does print “YES” otherwise print “NO”.

Input
The first line contains an integer N (1≤N≤500)N\
(1 ≤ N ≤ 500) — the number of elements in the
array. (1\le
N\le
The second line containsNN N integers A(1≤A[i]≤103).A\hspace{0.2c
500) — the elements of the array A (1 ≤ A[i] ≤
3 (1
10 ).
\le
The third line contains single integers X.X.
X. A[i]
\le
Output 10^3).
If the numberXX
X is present in the array print “YES”, otherwise print “NO”, without
quotations.

Samples
Input Output
10 YES
4 2 6 4 8 3 9 4 2 6
2

Be careful about the newline(‘\n’) at the end.

DIU Unlock the Algorithm Programming Contest Fall-... | Toph 15 of 15

You might also like