Problems

Pick a problem and write your solution in the built-in editor. The judge runs it against real test cases while you watch, and the wider archive is open to read whenever you like.

Total results3,779 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Emergency ResponseGiven a directed weighted graph, answer multiple queries: the shortest travel time from any of several start nodes to one crime intersection.Medium4GraphShortest path+2No attempts yet1s128 MBJudgeable
Open IntervalsGiven up to 50 open intervals per test case, pick the largest subset where no two intervals overlap, counting touching endpoints as compatible.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Next PermutationGiven an integer A, find the smallest permutation of its digits that is strictly greater than A, or print USELESS if none exists.Medium4ArrayString+2No attempts yet1s128 MBJudgeable
Stacking BooksGiven a stack of book sizes, find the fewest moves that pull one book to the top (only when the part above it is non-decreasing) to sort the stack.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
The Best PizzaChoose any subset of toppings, each costing B, to maximize total calories divided by total price, and print the floor of that ratio.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Tornado!Given a circular fence of N posts marked standing or broken, choose the fewest broken posts to fill so no wire span between standing posts exceeds 4 meters.Medium4GreedyArray+2No attempts yet1s128 MBJudgeable
Cow CrossingsCount cows whose straight crossing paths intersect no other cow, where two paths cross exactly when the start and end left-to-right orders differ.Medium4SortingArray+2No attempts yet1s128 MBJudgeable
GiftGiven each friend's item price and shipping cost and one coupon that halves a single item price, find the most gifts buyable within budget B.Medium4SortingGreedy+2No attempts yet1s128 MBJudgeable
Heat WaveGiven an undirected weighted graph, find the minimum total cost of a route from a source town to a destination town.Medium4GraphShortest path+2No attempts yet1s128 MBJudgeable
Selfish GrazingGiven N intervals, find the maximum number of intervals that can be chosen so that no two of them overlap.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Chocolate BuyingGiven N chocolate types with a cost per piece and a number of cows wanting each, spend a budget B to satisfy as many cows as possible.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Maximize the AccelerationGiven N parts that each add force and mass, choose the subset maximizing total force divided by total mass, breaking ties by smaller mass.Medium4Brute forceBit manipulation+2No attempts yet1s128 MBJudgeable
The Widest MountainGiven a sequence of heights, find the longest contiguous run that is non-decreasing then non-increasing; valleys are shared by both neighboring mountains.Medium4ArrayImplementation+2No attempts yet1s128 MBJudgeable
Mountain WatchingGiven a sequence of heights, find the longest consecutive block that rises (non-strictly) then falls (non-strictly), allowing a block that only rises or only falls.Medium4ArrayTwo pointers+2No attempts yet1s128 MBJudgeable
Time ManagementGiven each chore's duration and deadline, find the latest start time that lets John finish all chores before their deadlines, or print -1.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
ScrabbleGiven a tray of T letters (some blanks that score 0) and an alphabetized dictionary, pick the highest-scoring dictionary word formable from the tray, breaking ties alphabetically.Medium4StringGreedy+2No attempts yet1s128 MBJudgeable
O Those FadsCows join a fad when its attractiveness L reaches their resistance; each joiner raises L by K. Count the final number of participants.Medium4SortingGreedy+2No attempts yet1s128 MBJudgeable
Speed ReadingFor each cow, simulate reading in bursts of at most T minutes with R-minute rests between, and report the total minutes rounded up to finish N pages.Medium4SimulationImplementation+2No attempts yet1s128 MBJudgeable
Bookshelf 2Given up to 20 cow heights and a target bookshelf height B, find the minimum amount by which some subset's total height exceeds or equals B.Medium4Brute forceBit manipulation+2No attempts yet1s128 MBJudgeable
Election TimeEach cow has first round votes A and second round votes B; the top K by A advance, then the one with the largest B among them wins. Output the winner's index.Medium4SortingArray+2No attempts yet1s128 MBJudgeable
iCowRepeatedly pick the highest-rated song, reset its rating to 0, and spread its points over the others until T songs are played.Medium4SimulationImplementation+1No attempts yet1s128 MBJudgeable
Dining CowsGiven a sequence of 1s and 2s, find the minimum number of values to change so the sequence becomes nondecreasing.Medium4Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Clear and Present DangerGiven a danger matrix and a required sequence of islands, find the minimum total danger of a walk that visits those islands in order, allowing detours through others.Medium4GraphShortest path+2No attempts yet1s128 MBJudgeable
Buy One Get One FreeBuy all N high quality bales, then pair as many of the M low quality bales as possible so each free bale is strictly smaller than its distinct high quality partner. Output N plus the maximum number of pairs.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
Bronze Cow PartyGiven a connected undirected weighted graph, find twice the largest shortest-path distance from a fixed farm X, which is the longest round trip any cow makes.Medium4Shortest pathGraph+2No attempts yet1s128 MBJudgeable
Team ArrangementPick the lowest-numbered players for each role to match a formation, then name the selected player with the most years served as captain.Medium4SortingGreedy+2No attempts yet1s128 MBJudgeable
Suspicious StocksGiven daily stock prices and starting cash, buy as many whole shares as possible on one day, then sell all on a later day, and report the maximum profit.Medium4ArrayBrute force+2No attempts yet1s128 MBJudgeable
BudgetGiven row sums, column sums, and bound constraints on individual cells or whole rows/columns, decide whether a matrix of non-negative integers exists.Medium4GreedyMath+1No attempts yet1s256 MBJudgeable
It’s tough being a teen!Given a fixed list of seven tasks with precedence rules plus up to ten extra constraints, output a valid order using the smallest available task first, or report that no order exists.Medium4GraphTopological sort+2No attempts yet1s128 MBJudgeable
GolfGiven a target distance and up to 32 distinct club distances, find how many strokes give an exact sum, using unlimited repeats of each club.Medium4Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Maximum DistanceGiven two non-increasing arrays, find the largest j - i such that j >= i and Y[j] >= X[i].Medium4ArrayTwo pointers+2No attempts yet1s128 MBJudgeable
Bad CowtractorsGiven an undirected weighted graph, find a spanning tree of maximum total edge cost, or report -1 if no spanning tree exists.Medium4Minimum spanning treeGreedy+2No attempts yet1s128 MBJudgeable
Milk and HoneyAssign each field to cows or bees to maximize total happiness, where each field's output value declines linearly with each added unit.Medium4GreedyMath+1No attempts yet1s1024 MBJudgeable
Cosmic AssemblyFind integer coordinates (x, y, z) minimizing the sum of Manhattan distances to N given points, breaking ties lexicographically.Medium4MathSorting+1No attempts yet1s1024 MBJudgeable
BossesGiven a graph of projects where the lower-numbered endpoint is the boss, find the max number of edges so every vertex has at most one boss, minimizing cancellations.Medium4GraphGreedy+2No attempts yet1s1024 MBJudgeable
InternetGiven measurements with connection states, where the first and last show a connection, find the longest possible time the connection could have been down.Medium4GreedyImplementation+1No attempts yet1s1024 MBJudgeable
Rotten RopesGiven the tear-off weights of n ropes, find the maximum object weight that a chosen subset can carry so that no rope in the subset breaks.Medium4GreedySorting+2No attempts yet1s128 MBJudgeable
ParliamentSplit N delegates into groups of distinct sizes so that the product of the sizes is maximized, and print the sizes in ascending order.Medium4MathGreedy+1No attempts yet1s128 MBJudgeable
BukazoidsGiven cell counts and a fixed number of single and double jumps, maximize collected bukazoids and output the lexicographically smallest optimal visit sequence.Medium4Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Holiday GiftsAssign one of two priced gifts to each node of a rooted tree so no two adjacent employees share a gift, minimizing total cost.Medium4TreeDynamic programming+2No attempts yet1s128 MBJudgeable
Gathering PointsGiven M points on an N by N grid, find a cell minimizing the sum of Manhattan distances from all points to it.Medium4MathSorting+1No attempts yet1s256 MBJudgeable
Dreadful DeadlinesGiven n jobs with durations and deadlines, find the latest start time from which all jobs can still be finished by their deadlines.Medium4GreedySortingNo attempts yet1s128 MBJudgeable
Baking CakesGiven up to 40 cake baking times and 3 ovens, find the minimum time to bake all cakes.Medium4Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Trigonometric OptimizationChoose positive integers x, y, z summing to S to optimize sin/cos(x)+sin/cos(y)+sin/cos(z), rounded to 10 decimals.Medium4MathBrute force+1No attempts yet2s128 MBJudgeable
Minimum SwapsFor each string of distinct lowercase letters, find the minimum number of arbitrary swaps needed to sort it into alphabetical order.Medium4SortingGreedy+2No attempts yet1s128 MBJudgeable
Longest Ordered SubsequenceGiven a sequence of N integers, find the length of the longest non-decreasing subsequence.Medium4Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Holiday CostingFor each stay length at a hotel, choose one stay/pay deal, repeated as allowed, to minimize the nights you pay for.Medium4Brute forceImplementation+2No attempts yet1s128 MBJudgeable
CanoesGiven a canoe weight limit and each participant's weight, find the minimum number of two-person canoes needed to carry everyone.Medium4GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
TrianglesGiven a list of segment lengths, find the largest perimeter of a non-degenerate triangle formed by three of them, or print NIE if none exists.Medium4SortingGreedyNo attempts yet1s128 MBJudgeable
Grid Shading PuzzleGiven per-row and per-column shaded counts for an n by n board, decide whether a valid 0/1 board exists.Medium4GreedySortingNo attempts yet1s128 MBJudgeable
SingingThe task is to place the fewest books so every student in a row has one or sits next to one.Medium4GreedyNo attempts yet1s512 MBJudgeable
CoinsCount the ways to place coins of sizes 1 to n into slots with capacities a_i so every coin fits, modulo 1000000007.Medium4SortingCombinatorics+1No attempts yet1s512 MBJudgeable
TrainCount the fewest round trips a train needs to drop its wagons from the back at their assigned cities in order.Medium4GreedyHash mapNo attempts yet1s512 MBJudgeable
DrawersPush as few drawers in as possible so the pull-out lengths strictly increase from the top drawer down.Medium4GreedyArrayNo attempts yet1s128 MBJudgeable
Exam PreparationSchedule preparation days before each exam day and find how many days before the earliest exam study must start.Medium4GreedySortingNo attempts yet1s128 MBJudgeable
Match MakerPair N men with N women from full preference lists to output the man-optimal stable matching with no blocking pair.Medium4SimulationGreedyNo attempts yet1s128 MBJudgeable
Hotel ReservationsFind the fewest rooms that fit all reservations when a room freed at checkout needs C more minutes of cleaning.Medium4IntervalsSorting+2No attempts yet2s128 MBJudgeable
Network PlanningPick M cities for new stations to maximize total supply, where each station covers 70 percent of its own demand plus 10 percent of each neighbor's.Medium4GreedySorting+1No attempts yet2s64 MBJudgeable
A site just for programming contestsBuy each plot in decreasing price order, one per year, and report the total cost or Too expensive when it exceeds the budget.Medium4GreedySorting+1No attempts yet1s128 MBJudgeable
Handing Out BooksAssign each applicant at most one distinct book numbered within their requested interval to maximize the number of satisfied applicants.Medium4GreedyIntervals+1No attempts yet2s256 MBJudgeable
NASSA's RobotYou get a walk of UDLR steps with ? wildcards that can stop after any prefix, and you report the smallest and largest reachable X and Y.Medium4GreedySimulationNo attempts yet1s128 MBJudgeable
Lottery 2Change as few entries as possible in a length-n sequence over 1 to k so no two adjacent entries are equal.Medium4GreedyArrayNo attempts yet1s128 MBJudgeable
Rearranging a Bit StringFind the fewest adjacent swaps turning the start bits into one of the strings matching the run code.Medium4GreedyBrute forceNo attempts yet1s256 MBJudgeable
Train TravelCount how many times each rail is crossed and pay the cheaper of single tickets or a discount card plus cheap fares for every rail.Medium4Prefix sumGreedyNo attempts yet1s256 MBJudgeable
AirportEach arriving plane takes the largest free gate up to its limit gi, and the count stops at the first plane with no free gate.Medium4Union-findGreedyNo attempts yet1s256 MBJudgeable
NetworkAdd the fewest edges to a tree so it stays connected after any single edge breaks, pairing leaves in the prescribed DFS order.Medium4TreeDFS+1No attempts yet1s256 MBJudgeable
Classroom assignmentGiven N class time intervals, find the smallest number of rooms so overlapping classes never share a room.Medium4GreedySorting+2No attempts yet1s256 MBJudgeable
Jump JumpStarting from the first cell, find the fewest rightward jumps bounded by each cell value to reach the last cell, or -1 when unreachable.Medium4Dynamic programmingGreedyNo attempts yet1s256 MBJudgeable
Dr Who's BanquetBuild a chat graph whose vertex degrees equal the given wishes with the stated greedy construction, or print fail.Medium4GraphGreedy+1No attempts yet1s256 MBJudgeable
Icelandic MotorclubsFind the smallest-numbered station from which a rider who takes all gas at every stop can complete one clockwise lap.Medium4GreedyPrefix sumNo attempts yet3s256 MBJudgeable
Popping BalloonsPop every balloon from left to right with the fewest rightward arrows that drop one unit after each hit.Medium4GreedyHash mapNo attempts yet2s256 MBJudgeable
CompetitionFind the fewest seat changes that let Alice and Bob solve every solvable problem in contest order.Medium4GreedySortingNo attempts yet1s256 MBJudgeable
ExcellencePair all students into teams of two so the smallest team rating sum is as large as possible.Medium4GreedySorting+1No attempts yet2s256 MBJudgeable
GeneratorsSimulate each bounded generator to find its largest reachable value, then lower one value by the smallest loss that breaks divisibility by k.Medium4GreedySimulationNo attempts yet1s256 MBJudgeable
Birthday Numbers IFind the numerically smallest number made only of digits 3, 5 and 8 whose digits add up to N, or -1 when none exists.Medium4GreedyMathNo attempts yet1s256 MBJudgeable
High Card WinsAssign each of Bessie's N cards to a round against Elsie's fixed play order to win the most rounds with the higher card.Medium4GreedySortingNo attempts yet2s512 MBJudgeable
Angry Cows (Silver)Find the smallest integer blast radius R so K intervals of length 2R cover all N hay bale positions on a line.Medium4Binary searchGreedy+1No attempts yet2s512 MBJudgeable
Mileage Course RegistrationGiven each course rival bids and capacity, bid 1 to 36 points per chosen course, winning ties, to take the most courses with m points.Medium4GreedySortingNo attempts yet1s128 MBJudgeable
TelephonesAdd the fewest phones to empty desks so a ring hops from the first desk to the last with each hop spanning at most D.Medium4GreedyArrayNo attempts yet1s64 MBJudgeable
Mushroom Monster (Large)From plate counts taken every 10 seconds, compute the minimum mushrooms eaten under free eating and under the smallest consistent constant rate.Medium4GreedySimulation+1No attempts yet5s512 MBJudgeable
Packing Files onto DiscsPack all files onto the fewest discs of capacity X with at most two files per disc.Medium4GreedyTwo pointers+1No attempts yet5s512 MBJudgeable
Data PackingPack files onto discs holding at most two files of total size X using the fewest discs.Medium4GreedyTwo pointers+1No attempts yet5s512 MBJudgeable
Cookie FarmsDecide how many cookie farms to buy before waiting so the time to hold X cookies is as short as possible.Medium4GreedyMathNo attempts yet5s512 MBJudgeable
Lawnmower (Small)Decide if row and column cuts of a mower that only lowers grass can produce the given target heights from a uniform lawn.Medium4GreedyMatrixNo attempts yet5s512 MBJudgeable
Lawnmower (Large)Decide whether a target grid of grass heights is reachable from height 100 by cutting whole rows or columns down to chosen levels.Medium4GreedyMatrixNo attempts yet5s512 MBJudgeable
Dancing With the Googlers (Small)Given each dancer's total of three judge scores and a budget of surprising triplets, maximize the count of dancers whose best score reaches p.Medium4GreedyMathNo attempts yet5s512 MBJudgeable
Dancing With the Googlers (Large)Given each dancer's total of three close scores and a limit on surprising splits, count the most dancers that reach a best score of p.Medium4GreedyNo attempts yet5s512 MBJudgeable
Closing the Loop (Small)Pick equal numbers of red and blue segments with the largest lengths and subtract one centimeter per knot to get the longest alternating loop.Medium4GreedySortingNo attempts yet5s512 MBJudgeable
Painting a fence (small)From up to 10 offers, choose the fewest that cover sections 1 to 10000 using at most 3 distinct colors.Medium4Brute forceIntervals+1No attempts yet5s512 MBJudgeable
Minimum Keypresses for Text EntryAssign each letter to a key and a position so that total presses, the frequency times the position, is minimized.Medium4GreedySorting+2No attempts yet5s512 MBJudgeable
Minimum Scalar Product (Small)Permute two vectors to minimize their dot product and print the minimum.Medium4SortingGreedy+1No attempts yet5s512 MBJudgeable
Minimum Scalar Product (Large)Reorder the coordinates of two equal-length integer vectors so their scalar product is as small as possible, and report that minimum for each test case.Medium4SortingGreedy+2No attempts yet5s512 MBJudgeable
Milkshakes (Large)Assign each of N flavors malted or unmalted so every customer gets a liked type, using the fewest malted batches, or report IMPOSSIBLE.Medium4GreedyImplementationNo attempts yet5s512 MBJudgeable
Train Timetable (Small)Given a day's timetable and a turnaround time, find the minimum number of trains that must start the day parked at each of the two stations.Medium4GreedySorting+2No attempts yet5s512 MBJudgeable
Train Timetable (Large)Given each train's departure and arrival times plus a turnaround time, find the minimum trainsets needed at stations A and B to run the timetable.Medium4GreedySorting+1No attempts yet5s512 MBJudgeable
Bit Friendship IndexGiven two equal-length binary strings, find the minimum number of digit changes and character swaps to make them identical.Medium4StringGreedy+1No attempts yet1s128 MBJudgeable
Road Network of a Perfect Binary TreeFind the minimum number of cars whose vertex-disjoint paths cover every vertex of a perfect binary tree of height H exactly once.Medium4TreeDynamic programming+1No attempts yet2s512 MBJudgeable
A Restaurant for BearsEach arriving bear takes the smallest empty chair at or above its wanted number that is at least d away from every seated bear.Medium4ImplementationGreedy+1No attempts yet2s512 MBJudgeable
Tree and paths of length twoDecide whether some tree on N nodes has exactly S simple paths of length 2.Medium4TreeCombinatorics+1No attempts yet2s512 MBJudgeable
ABCFind the lexicographically smallest length-N string over A, B, C that has exactly K pairs i < j with S[i] < S[j].Medium4GreedyCombinatorics+1No attempts yet2s512 MBJudgeable