Sample Test 1:: N I Power Bonus Power
Sample Test 1:: N I Power Bonus Power
Sample Test 1:: N I Power Bonus Power
Sample test 1:
Hardest Quest:
While playing an RPG game, you were assigned to complete one of the hardest quests in this game.
There are n monsters you'll need to defeat in this quest. Each monster i is described with two integer
numbers - poweri and bonusi. To defeat this monster, you'll need at least poweri experience points. If
you try fighting this monster without having enough experience points, you lose immediately. You will also
gain bonusi experience points if you defeat this monster. You can defeat monsters in any order.
The quest turned out to be very hard - you try to defeat the monsters but keep losing over and over again.
Your friend told you that this quest is impossible to complete. Knowing that, you're interested, what is the
maximum possible number of monsters you can defeat?
Input:
he first line contains an integer, n, denoting the number of monsters.
The next line contains an integer, e, denoting your initial experience.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, poweri, which represents
power of the corresponding monster
Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, bonusi, which represents
bonus for defeating the corresponding monster.
Sample Cases:
Input Output Output Description
2 2 Initial experience level is 123 points.
123
78 Defeat the first monster having power of 78 and bonus of 10. Experience level
130
is now 123+10=133.
10
0
Defeat the second monster.
3 2 Initial experience level is 100 points.
100
101 Defeat the second monster having power of 100 and bonus of 1. Experience
100
level is now 100+1=101.
304
100
1 Defeat the first monster having power of 101 and bonus of 100. Experience
524 level is now 101+100=201.
Alex is very patient, so he managed to do this. Now you're wondering, how many different arrays are
written down on this paper?
Since the answer can be really large, print it modulo 10000.
Input:
The first line contains an integer, n, denoting the maximum possible value in the arrays.
The next line contains an integer, k, denoting the length of the arrays.
Sample Cases:
Input Output Output Description
2 2 The required length is 1, so there are only two possible arrays: [1] and [2].
1
2 3 All possible arrays are [1, 1], [1, 2], [2, 2].
2 [2, 1] is invalid because 1 is not divisible by 2.
3 5 All possible arrays are [1, 1], [1, 2], [1, 3], [2, 2], [3, 3].
2
2. Sample Test 2:
Bitwise subsequence
You have an array A of N integers A1 A2 .. An. Find the longest increasing subsequence Ai1 Ai2 .. Ak (1 <= k
<= N) that satisfies the following condition:
• For every adjacent pair of numbers of the chosen subsequence Ai[x] and Ai[x+1] (1 < x < k), the expression(
Ai[x] & Ai[x+1] ) * 2 < ( Ai[x] | Ai[x+1] ) is true
Note: '&' is the bitwise AND operation, ' | ' is the bit-wise OR operation
Input:
The first line contains an integer, N, denoting the number of elements in A.
Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer describing Ai.
Sample Cases:
Input Output Output Description
5 2 One possible subsequence is:
15 5 12
6
5
12
1
Grid Path
Given a grid. Each cell of the grid contains a single integer value. These values are described by 2D
integer array a with N rows and 2 columns, where a[i][j] is the value in the cell located in row i, column j.
Standing in (i; j), the player can move to any cell of the next row (i+1; j2) under the condition that
a[i+1][j2] > a[i][j]. In other words, the value in the next cell of the player's path should be strictly greater
than the value in the current cell of the player's path.
The player can't make any moves if he's already in the last row.
If the player starts in any cell of the first row (either (1; 1) or (1; 2)), what is the maximum possible total
sum of values in all cells he can visit on his path?
Sample Cases:
Input Output Output Description
2 6 Optimal path is (1;2)->(2;2).
1 2 The answer is 2+4=6.
3 4
2 8 No moves are possible from the first row. So start in (1; 2) and collect just 8.
7 8
5 5