It is 2067 and the fine astronauts Adrian and Ashton just landed on Venus, marking a significant step forward in space exploration for mankind! However, they are currently having a dispute trying to figure out who should get the honor of being the first to touch down on the surface. To prevent further arguing, their advisor Maverick suggests that they play the following game to decide.
In this game, there is an array $$$a$$$ of $$$3n$$$ $$$(1 \leq n \leq 10^5)$$$ numbers. In each round:
This process repeats until there are no elements left in $$$a$$$, at which point the game ends.
Adrian and Ashton both want to maximize their score, as the player with the higher score at the end of the game wins. If Adrian and Ashton play optimally, what score will both of them have at the end of the game?
$$$^\dagger$$$Given an array $$$a$$$ of size $$$k$$$, a cyclic shift of $$$a$$$ turns $$$[a_1, a_2, ..., a_{k-1}, a_k]$$$ into $$$[a_k, a_1, a_2, ..., a_{k-1}]$$$
The first line contains an integer $$$n$$$, where $$$a$$$ is of size $$$3n$$$
The second line contains $$$3n$$$ integers, $$$[a_1, a_2, ... a_{3n}]$$$ $$$(1 \leq a_i \leq 10^9$$$), the elements in $$$a$$$.
Output two numbers, Adrian's score and Ashton's score if both play optimally.
110 5 10
20 15
23 8 5 4 10 1
27 12
In the first test case, in the first round it is optimal for Adrian to leave the array as is and select indices $$$i = 1, j = 3$$$. Thus Ashton only has one choice for $$$k$$$, which is $$$2$$$.
After this round, Adrian's score is $$$10 + 10 = 20$$$, and Ashton's score is $$$5 * 3 = 15$$$.
After removing indices $$$1, 2, 3$$$ from the array, it is empty, and thus the game ends. So these are Adrian and Ashton's final scores.
In the second test case, one sequence of operations leading to the optimal scoring is as follows:
Round 1:
Thus Adrian's score at the end is $$$10 + 8 + 4 + 5 = 27$$$, and Ashton's score is $$$3 * 3 + 1 * 3 = 12$$$.
Warith has been coping for a while about not being able to see Le Sserafim in Dallas, so he decided to take a mental break. He decided to go down to the Colorado River and skip some stones. When he arrived, he found $$$n$$$ stones arranged in a line. Warith knows that each stone has some mass $$$a_i$$$ $$$(1 \le i \le n)$$$. With all the stuff on his mind, he wants to maximize his enjoyment from skipping stones by picking a contiguous subarray $$$a'$$$ of the original stone array. Note that Warith cannot rearrange the stones, he can only pick a contiguous subarray from the original order.
For an array $$$a'$$$, the enjoyment from skipping all these stones is calculated as follows:
The only issue is that Warith also does not want the mass of the stones to vary too much either. Specifically, he doesn't want his subarray to contain more than $$$k$$$ distinct masses. With this in mind, can you help Warith maximize his enjoyment?
The first line of input will contain two integers $$$n$$$ ($$$1 \le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le n$$$): the number of stones, and the max number of permitted unique masses.
The second line contains $$$n$$$ integers ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the mass of the $$$i$$$th stone.
Output a single integer $$$E$$$: the maximum enjoyment Warith can achieve.
8 31 7 2 3 2 2 1 7
16
In the sample test case, the optimal range is $$$[7, 2, 3, 2, 2]$$$, which has enjoyment $$$(7)(1) + (3)(1) + (2)(3) = 16$$$.
In the solar system, it is often said that the most habitable planet besides Earth is Mars. Indeed, scientists have recently begun settling on Mars and have set up a base for permanent living. However, while Mars has an abundance of water and soil nutrients, it's missing the greatest natural resource: Milk! Unfortunately, this means that the scientists must import milk from Earth in order to sustain themselves.
Johnny, one of the scientists, has a particular affinity for milk. He has knowledge of spaceship trips which can transport jugs of milk from Earth to Mars and vice versa. Each of these trips has a departure and arrival time, and all of these times are distinct from each other.
Due to restrictions regarding waste, in order to import milk, Johnny must place an empty jug of milk on a spaceship bound for Earth where it will be filled immediately. He can then request for a particular spaceship bound for Mars to carry the milk back, where Johnny can empty the milk jug in a large storage container. Each spaceship can only carry one of Johnny's milk jugs at most (other scientists want to use the spaceships as well!).
Before any of the spaceships begin transporting items, Johnny has two empty milk jugs on hand. Given this knowledge, Johnny would like to know the maximum jugs' worth of milk he can import from Earth with the spaceships available.
The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of spaceship trips.
The next $$$n$$$ lines each contain three integers describing a spaceship trip, with the $$$i$$$-th line containing $$$l_i$$$, $$$r_i$$$, and $$$t_i$$$ ($$$0 \le l_i \lt r_i \le 10^9$$$, $$$t_i \in \{0, 1\}$$$) — the departure time, the arrival time, and the trip type, respectively. If $$$t_i = 0$$$, the trip is bound for Earth, and if $$$t_i = 1$$$, the trip is bound for Mars.
Output a single integer — the maximum jugs' worth of milk that Johnny can import from Earth.
40 1 02 3 14 5 06 7 1
2
60 4 07 8 11 5 09 10 12 6 011 12 1
2
In the first test case, Johnny can place an empty milk jug on the spaceship departing at time $$$0$$$ for Earth, and schedule it to return on the spaceship departing at time $$$2$$$ for Mars. He can then empty that milk jug in storage, place it on the spaceship departing at time $$$4$$$ for Earth, and schedule it to return on the spaceship departing at time $$$6$$$ for Mars. The filled milk jug will then be emptied into Johnny's storage. In total, Johnny will have $$$2$$$ jugs' worth of milk in storage after all trips have occurred.
In the second test case, Johnny can schedule his trips as follows:
Jupiter is home to the largest Coriolis forces in the Solar System. Specifically, the Coriolis force causes horizontal bands on the planet to experience strong winds either East or West. Jupiter has $$$8$$$ of these prominent bands.
Embarking on a mission to navigate Jupiter, you are well aware of winds and need to factor them into the amount of fuel you need to bring on your mission. Your spaceship will enter Jupiter at coordinate $$$S$$$, and need to end at coordinate $$$D$$$. A coordinate can be denoted by the band you are in (vertical position), and the columns (horizontal position) along that band at time $$$t=0$$$.
Each timestep, the Coriolis winds take effect, rotating all positions of even-indexed bands right, and all positions of odd-indexed bands left.
Jupiter also has numerous storms that move along with these bands. You want to avoid these storms at all costs.
Consider the following 4 banded system example, as we can find on Earth:
col1 col2 col3 col4 col5
band1 | . | X | . | D | . | <–
band2 | X | . | X | X | X | –>
band3 | . | S | . | . | . | <–
band4 | . | . | . | . | . | –>
After one timestep, the world would look like:
col1 col2 col3 col4 col5
band1 | X | . | D | . | . | <–
band2 | X | X | . | X | X | –>
band3 | S | . | . | . | . | <–
band4 | . | . | . | . | . | –>
Your spaceship lets you move one tile in any cardinal direction (not diagonally) before the Coriolis effect takes effect each timestep. Note you can also choose to not move, in which you move along with the band. Also, note that columns 1 and $$$N$$$ are adjacent, but band1 and band8 are not.
Find the minimum amount of timesteps to travel from coordinate A to coordinate B (if possible) so we can know how much fuel to bring!
The first line contains $$$N$$$, the number of horizontal positions in each band. $$$1 \leq N \leq 3 \cdot 10^3$$$
The next $$$8$$$ lines each contain $$$N$$$ space-separated characters, with each line denoting the state of the world in that band at $$$t=0$$$. The character at the $$$i$$$th position on a line represents column $$$i$$$ in that corresponding band.
Output one integer, representing the minimum amount of timesteps required to travel from start to destination, or -1 if impossible.
5 X X X X X X X X X X . X . D . X . X X X . S . . . . . . . . X X X X X X X X X X
2
5 S . . . . . X X X X X X . X X X X X . X X X X X . X . X X X X . X X X X X X X D
7
For explaining the first sample, let $$$(x,y)$$$ be the coordinate that is in the $$$x$$$th band and the $$$y$$$th column (both $$$1$$$-indexed).
It can be shown this is the fastest way to reach the destination.
Note: The following problem, Uranus, may be easier if you prefer solving in order of increasing difficulty.
Christiaan Huygens was the first to propose there was a ring surrounding Saturn, in 1655. He did this by publishing his claim as an anagram: aaaaaaacccccdeeeeehiiiiiiillllmmnnnnnnnnnooooppqrrstttttuuuuu. Only three years later did he have enough evidence to publish the true claim: Annulo cingitur, tenui, plano, nusquam cohaerente, ad eclipticam inclinato ("It is encircled by a thin, flat ring, nowhere touching, inclined to the ecliptic").
Shani recently became inspired by Huygens and published some similar anagrammed claim. Unfortunately, it was mostly a joke, but now the research committee is calling upon her to back it up.
Luckily, she does have some data that she has yet to publish. Specifically, she has $$$1 \le n \le 1000$$$ data points, each a string $$$s_i$$$ with $$$1 \le |s_i| \le 100$$$. She may publish any subset of these data points, and once published, she knows the committee will concatenate them in their original order (the data points are dated). Her original claim is a string $$$t$$$ with $$$1 \le |t| \le 20$$$. The committee will then count how many times $$$t$$$ occurs as a substring in the published data (overlaps are counted), and for each occurrence she will earn one reputation score.
Report the maximum reputation score Shani can get.
The first line contains a string $$$t$$$ $$$(1 \le |t| \le 20)$$$ — Shani's original claim.
The next line contains an integer $$$n$$$ $$$(1 \le n \le 1000)$$$ — the number of data points.
The next $$$n$$$ lines each contain a non-empty string $$$s_i$$$ $$$(1 \le |s_i| \le 100)$$$ — the $$$i$$$-th data point, already listed in the order they were recorded.
All strings consist only of lowercase English letters.
Print a single integer — the maximum reputation score Shani can obtain.
lol3ololololo
3
ababac3abababaabac
1
For the first sample, publishing all three data points gives 3 reputation score: $$$\text{o}\color{red}{\text{lol}}\text{ololo}$$$ $$$\text{olo}\color{red}{\text{lol}}\text{olo}$$$ $$$\text{ololo}\color{red}{\text{lol}}\text{o}$$$
For the second, publishing the first and the last gives 1 reputation score: $$$\text{ab}\color{red}{\text{ababac}}$$$
Although it is not the farthest planet from the Sun, Uranus is considered to be the coldest planet in the Solar System, experiencing a minimum temperature of 49 K and extreme winds of up to 900 km/h. Undaunted, Sir Vedward V's twin brother, Sir Udward, wishes to send probes to explore Uranus.
Currently, VASA has developed $$$n$$$ probes, where the $$$i^{\text{th}}$$$ probe can survive temperatures of up to $$$x_i$$$ degrees Kelvin and wind speeds of up to $$$y_i$$$ km/h; however, it costs $$$c_i$$$ dollars to construct. In addition, VASA has conducted $$$q$$$ measurements of locations on Uranus, where the $$$i^{\text{th}}$$$ location has a temperature of $$$t_i$$$ degrees Kelvin and a wind speed of $$$w_i$$$ km/h.
Sir Udward will reward you handsomely if you help him determine, for each landing location, the cheapest probe that can survive its temperature and wind speed.
The first line of input contains $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 10^5$$$), the number of probes and locations, respectively.
The second line contains $$$n$$$ integers, $$$x_1, x_2, ..., x_n$$$ ($$$1 \le x_i \le 10^9$$$), the maximum temperature each probe can survive.
The third line contains $$$n$$$ integers, $$$y_1, y_2, ..., y_n$$$ ($$$1 \le y_i \le 10^9$$$), the maximum wind speed each probe can survive.
The fourth line contains $$$n$$$ integers, $$$c_1, c_2, ..., c_n$$$ ($$$1 \le c_i \le 10^9$$$), the cost of each probe.
The next $$$q$$$ lines each contain two integers $$$t_i$$$ and $$$w_i$$$ ($$$1 \le t_i, w_i \le 10^9$$$), the temperature and wind speed at the $$$i^{\text{th}}$$$ location, respectively.
The output should be $$$q$$$ integers, each on a separate line, the minimum cost of a probe that can survive for each location, or $$$-1$$$ if there is no probe that can survive.
3 31 2 33 1 23 2 11 21 33 3
1 3 -1
The first probe ($$$1 \ge 1$$$ and $$$3 \ge 2$$$) and third probe ($$$3 \ge 1$$$ and $$$2 \ge 2$$$) can both survive the first location, but the third probe is cheaper, so the output is $$$1$$$.
Only the first probe ($$$1 \ge 1$$$ and $$$3 \ge 3$$$) can survive the second location, so the output is $$$3$$$.
None of the probes can survive the third location, so the output is $$$-1$$$.
Recently, Poseidon has gotten addicted to a game called Craftmine. In Craftmine, there is a crafter that consists of $$$k$$$ slots, each of which can store an unlimited amount of a single type of ingredient. If the slot has 0 ingredients, it is considered empty. A recipe represents a configuration of the crafter that will produce a desired product. Each recipe is an array of length $$$k$$$ whose elements are either an empty slot or a type of ingredient.
Each time the crafter is used, it checks if the current configuration matches a recipe by comparing the ingredients in each of the slots (but not the amount of each ingredient). If the configuration matches a recipe, every slot uses up exactly 1 of the ingredients in that slot (except for empty slots, where nothing happens).
Currently, Poseidon has $$$n$$$ unique recipes and (being a god) has an unlimited amount of all ingredients. However, Poseidon is quite lazy, so he plans to fill the crafter only once, then use it as many times as he can to create unique recipes.
What is the maximum number of unique recipes that can be created after filling the crafter once?
Warning: Java and Python solutions are probably too slow for this problem.
The first line of input contains $$$n$$$ and $$$k$$$ $$$(1\leq n\leq 2000, 1\leq k\leq 2000)$$$.
The $$$i$$$th of the next $$$n$$$ lines contains recipe $$$i$$$, which is an array $$$a_i$$$ of $$$k$$$ integers, with 0 representing an empty slot, and all other numbers representing a type of ingredient $$$(0\leq a_{i,j} \leq 100)$$$.
Output a single integer, the maximum number of unique recipes that can be created after filling the crafter exactly once.
5 40 0 1 02 0 1 03 0 1 03 10 1 02 2 1 0
3
Poseidon can put 2 of item 3 in the 1st slot, 1 of item 10 in the 2nd slot, 3 of item 1 in the 3rd slot, and nothing in the 4th slot: $$$\{3_2, 10_1, 1_3, \emptyset\}$$$.
Using the crafter now will yield recipe 4 ($$$\{3,10,1,\emptyset\}$$$). After the ingredients are used up for the recipe, the crafter becomes $$$\{3_1,\emptyset, 1_2, \emptyset\}$$$.
Using the crafter now will yield recipe 3 ($$$\{3,\emptyset, 1, \emptyset\}$$$). After the ingredients are used up for the recipe, the crafter becomes $$$\{\emptyset, \emptyset, 1_1, \emptyset\}$$$.
Using the crafter now will yield recipe 1 ($$$\{\emptyset, \emptyset, 1, \emptyset\}$$$). After the ingredients are used for the recipe, the crafter becomes $$$\{\emptyset, \emptyset, \emptyset, \emptyset\}$$$).
At this point, no more recipes can be made. Since 3 unique recipes were made, the answer is 3.
Shortly after solving their previous dilemma, the Plutonian government has asked for your help once again. There is a special vault in the heart of the Plutonian capitol, and the government needs to unlock it (don't ask why), but the process of doing so is quite complex so they've requested your help.
The vault has a lock consisting of $$$n$$$ switches, numbered $$$1...n$$$, where $$$n$$$ is odd. The initial state of the lock is given as a bitstring of length $$$n$$$, where the $$$i$$$-th character represents the state of the switch $$$i$$$, and a '1' denotes that the switch is up while a '0' denotes that it is down. To unlock the safe, all of the switches need to be down. You want to unlock the lock, but you can only perform the following two operations on the lock:
The Plutonian government is short on time, so they want you to determine the minimum number of operations necessary to set all switches to the down ('0') state.
Of course it isn't that simple though. After all, the government is short on time because every minute for $$$q$$$ minutes the state of the lock changes. During the $$$i$$$th update, all switches $$$j$$$ such that $$$l_i \leq j \leq r_i$$$ are flipped. Note that the updates persist. Please help the Plutonians and output the minimum number of operations to set all switches to the down state after each update.
The first line of input will consist of two integers $$$n$$$ and $$$q$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq q \leq 2 \cdot 10^5$$$, $$$n$$$ is odd) — denoting the number of switches in the lock and the number of updates respectively.
The next line contains a bitstring $$$s$$$ of length $$$n$$$ ($$$s_i \in \{'0', '1'\}$$$) — denoting the state of the lock.
The $$$i$$$-th of the next $$$q$$$ lines contains integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$) — denoting that during the $$$i$$$-th update the state of the locks from $$$l_i$$$ to $$$r_i$$$ are flipped.
Output $$$q$$$ lines, each with a single integer denoting the minimum number of operations needed to unlock the lock after each update occurs.
7 311010104 71 35 6
3 4 3
9 20000000019 91 9
0 1