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 results225 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
Card Bundle SortingGiven N sorted card bundle sizes, find the minimum total comparisons to merge them all into one bundle using an optimal merge strategy (classic huffman-like heap problem).Easy3HeapGreedyNo attempts yet2s128 MBJudgeable
Minimum HeapImplement a min-heap to support inserting natural numbers and repeatedly extracting the smallest, printing 0 when empty.Easy3HeapImplementationNo attempts yet1s128 MBJudgeable
Cracking Tree CodesGiven a tree and its leaf-stripping code with some entries erased, the program replays the encoding to recover the missing numbers.Easy3SimulationTree+1No attempts yet1s128 MBJudgeable
Max HeapProcess N insert and pop-max operations on an initially empty max heap, printing the maximum or 0 when empty.Easy3HeapNo attempts yet1s256 MBJudgeable
Absolute Value HeapProcess insert and pop-min-by-absolute-value operations on integers with a custom heap, printing 0 on empty pops.Easy3HeapNo attempts yet1s256 MBJudgeable
Shortest PathCompute single source shortest paths from a given vertex in a directed weighted graph with up to 20,000 vertices and 300,000 edges, printing INF for unreachable vertices.Medium4Shortest pathGraph+1No attempts yet1s256 MBJudgeable
Problem Solving OrderGiven N tasks and M precedence constraints, output a topological order that always picks the smallest available problem number next.Medium4Topological sortHeap+1No attempts yet2s128 MBJudgeable
Minimum Cost PathGiven a directed weighted graph of cities and bus routes, compute the minimum cost path from a start city to a destination city.Medium4Shortest pathGraph+1No attempts yet0.5s128 MBJudgeable
Double QueueProcess a stream of add/serve commands maintaining a dynamic set to pop and remove either the maximum or minimum priority client each query.Medium4HeapSorting+1No attempts yet1s128 MBJudgeable
ManagerSimulate a priority-based queue manager that adds costs, removes min or max cost per current policy, and prints results only for specified removal request indices.Medium4HeapSimulation+1No attempts yet1s128 MBJudgeable
Quick out of the HarbourFind the shortest time from S to outside the grid, where water cells cost 1 and drawbridges cost 1+d, on a grid up to 500x500.Medium4GraphShortest path+2No attempts yet1s128 MBJudgeable
Parking LotSimulate cars arriving and leaving a parking lot, assigning each to the lowest-numbered free space or a waiting queue, and sum weight times rate.Medium4SimulationQueue+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
ArgusGiven queries that each fire every Period seconds starting at time Period, output the Q_num of the first K results, breaking ties by smaller Q_num.Medium4HeapSimulation+1No 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
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
RestaurantsEvery city connects by weighted roads and some hold restaurants; report the largest distance from any city to its closest restaurant.Medium4Shortest pathGraph+1No attempts yet1s128 MBJudgeable
ExperimentOrient each undecided corridor so the whole maze stays acyclic, following the smallest-numbered topological order of the fixed corridors.Medium4Topological sortGraph+1No attempts yet3s128 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
Enterprise EscapeStarting from E, move four-directionally across the grid paying each entered cell's class cost and escape through the cheapest border cell.Medium4Shortest pathMatrix+1No attempts yet10s256 MBJudgeable
Triball RankingOrder all k players to satisfy every match result and return the lexicographically smallest lineup, or 0 when no lineup fits.Medium4Topological sortGraph+1No attempts yet2s512 MBJudgeable
HackingStarting from the hacked computer, count reachable computers through dependency edges and report the longest infection time.Medium4Shortest pathGraph+1No attempts yet2s256 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
Goods MarketProcess insertions, global rent hikes, and cheapest-shop evictions, then report how many shops remain and their total rent.Medium4HeapSimulationNo attempts yet1s256 MBJudgeable
Weekly MeetingFor each member's house, add the shortest distances to two fixed nodes and sum all results, counting unreachable as -1.Medium4Shortest pathGraph+1No attempts yet1s512 MBJudgeable
Merging Files 3Given K file sizes, find the minimum total cost of repeatedly merging two files where each merge costs the sum of their sizes.Medium4HeapGreedyNo attempts yet2s512 MBJudgeable
Contest ScoreSimulate reading problems in order but solving the shortest available one first, keeping at most k in memory, and report the total submission time.Medium4SimulationHeap+1No attempts yet2s512 MBJudgeable
The nearest convenience storeGiven an undirected weighted graph with some vertices marked as homes and others as stores, pick the home whose shortest-path distance to the nearest store is smallest, breaking ties by vertex number.Medium4GraphShortest path+2No attempts yet2s512 MBJudgeable
Christmas GiftsProcess visits in order: depots add gifts to Santa's collection, and each child takes the largest gift currently held.Medium4HeapSimulation+1No attempts yet2s512 MBJudgeable
The fastest road to BanikoaraGiven towns joined by undirected weighted roads, find the shortest travel distance between a named departure town and destination town.Medium4GraphShortest path+2No attempts yet2s512 MBJudgeable
Chonggang ChonggangRun a single-source shortest path from Jinseo's house, find the nearest type A and type B house, and report the closer type (A wins ties).Medium4Shortest pathGraph+2No attempts yet1s256 MBJudgeable
The Seven WarlordsGiven up to ten million student grades, output the seven lowest grades in increasing order, one per line. Ties on the cut line still yield exactly seven grades.Medium4SortingHeap+2No attempts yet10s256 MBJudgeable
Bathroom Stalls (Small1)Simulate K people choosing stalls by a fixed farthest-from-others rule and report the distances around the stall the last person takes.Medium4SimulationImplementation+2No attempts yet5s512 MBJudgeable
Greedy SchedulerAssign each queued customer to the free cashier with the smallest number, track busy times, and output the cashier for every customer.Medium4HeapSimulation+1No attempts yet1s512 MBJudgeable
PartyGiven a directed weighted graph, compute for each village the round-trip shortest time to a fixed village X and return the maximum over all villages.Medium5Shortest pathGraph+1No attempts yet1s128 MBJudgeable
Running MedianGiven integers one by one, output the running median (lower of the two middles when count is even) after each insertion.Medium5HeapSorting+1No attempts yet0.1s128 MBJudgeable
Products of PrimesFind the N-th smallest number that can be formed as a product of one or more (with repetition) of K given distinct primes, using a heap-based merge.Medium5HeapMath+1No attempts yet2s128 MBJudgeable
Running MediansGiven a sequence read one number at a time, output the running median every time an odd number of elements have been read.Medium5HeapImplementationNo attempts yet1s128 MBJudgeable
Beacon NetworkSimulate beacons that light up over time and archers who shoot arrows down a fixed priority list toward unlit targets, computing each beacon's lighting time.Medium5SimulationHeap+1No attempts yet1s128 MBJudgeable
Emergency RoomSimulate an emergency room where doctors pick the waiting patient with the highest-priority next treatment, and report each patient's release time.Medium5SimulationHeap+2No attempts yet1s128 MBJudgeable
TruckingFor each graph case, find the largest cargo height allowing a route, then the shortest route length among routes that allow it.Medium5GraphShortest path+2No attempts yet3s128 MBJudgeable
Chocolate GivingFor each of B queries on a weighted undirected graph, output the shortest distance from pasture P to pasture Q that passes through the barn at pasture 1.Medium5GraphShortest path+2No attempts yet1s128 MBJudgeable
Best SpotGiven a weighted undirected graph and a set of favorite vertices, find the vertex whose average shortest-path distance to all favorites is smallest, breaking ties by smallest index.Medium5GraphShortest path+2No attempts yet1s128 MBJudgeable
Fence RepairSplit one board into N planks of given lengths; each cut costs the length of the piece being cut, so find the minimum total cost.Medium5GreedyHeap+2No attempts yet1s128 MBJudgeable
EntropyFor each line of text, print the fixed 8-bit ASCII bit length, the optimal prefix-free Huffman bit length, and the compression ratio rounded to one decimal.Medium5GreedyHeap+2No attempts yet1s128 MBJudgeable
Decode the TreeGiven a Prüfer code, rebuild the labeled tree on n vertices and print it as a canonical rooted word with children sorted by number.Medium5TreeHeap+2No attempts yet1s128 MBJudgeable
Tournament RankingGiven game results between teams, produce the lexicographically smallest topological order, or report that no valid ranking exists due to a cycle.Medium5GraphTopological sort+2No attempts yet1s128 MBJudgeable
CourierSimulate orders arriving over time: assign each to the free courier who delivers fastest, or drop it if all couriers are busy, and total each courier's earnings.Medium5SimulationImplementation+2No attempts yet1s1024 MBJudgeable
Playground HideoutGiven a directed graph with weighted edges and direct ground costs per node, find the index of the node with the largest shortest-path distance from ground, breaking ties by smallest index.Medium5Shortest pathGraph+2No attempts yet1s128 MBJudgeable
Traffic EngineeringGiven a directed network of named hosts where nodes cost 0 or 1 depending on ownership, report the cheapest route cost between each source-destination pair.Medium5GraphShortest path+2No attempts yet1s256 MBJudgeable
Dual Priority QueueProcess a sequence of insert and min/max delete operations on a dual priority queue, then report the remaining max and min.Medium5HeapImplementationNo attempts yet6s256 MBJudgeable
PromotionEach day, receipts are added to a box, then the largest and smallest are removed and the difference is paid out; find the total payout.Medium5HeapImplementation+2No attempts yet1s128 MBJudgeable
LibraryMerge n files two at a time, where each merge costs the sum of the two lengths, and minimize the total cost.Medium5GreedyHeapNo attempts yet1s128 MBJudgeable
Galactic Container ShipGiven M rails with height limits 1..M and N plates each worth its quality w and having height h, choose plates to maximize total quality so that each chosen plate fits some distinct rail.Medium5GreedySorting+1No attempts yet1s128 MBJudgeable
Portal KombatHektor absorbs the strength of each weaker opponent he beats, and the goal is the fewest wins that let him defeat the strongest opponent.Medium5GreedySorting+1No attempts yet5s128 MBJudgeable
Gone FishingSplit limited fishing time across roadside lakes with travel costs and declining catches to maximize total fish.Medium5GreedyHeap+1No attempts yet1s128 MBJudgeable
Milk SchedulingSchedule at most one cow per time unit before its deadline to maximize total gallons of milk.Medium5GreedyHeap+1No attempts yet1s128 MBJudgeable
SightseeingFrom node 1, route each destination along roads to make the weakest road on the path as strong as possible.Medium5HeapMinimum spanning tree+1No attempts yet3.5s512 MBJudgeable
Where's That Fuel?Starting with planet P's fuel, repeatedly visit affordable planets to maximize final fuel, then the number of visits.Medium5GreedySorting+1No attempts yet2s256 MBJudgeable
Bank QueuePick at most one person per minute before each deadline to maximize the total cash collected.Medium5GreedyHeap+1No attempts yet1s256 MBJudgeable
Entertainment BoxSchedule the most TV shows on k recorders so no recorder tapes overlapping shows.Medium5GreedySorting+1No attempts yet2s256 MBJudgeable
Song TitlesRearrange each title into the lexicographically smallest anagram with no equal adjacent letters, or report IMPOSSIBLE when none exists.Medium5GreedyHeap+1No attempts yet1s256 MBJudgeable
Insider's InformationFollow the given removal order, then insert each university at the front or back to satisfy at least half the betweenness triples.Medium5SimulationGreedy+2No attempts yet2s256 MBJudgeable
Workstation assignmentSeat each arriving researcher at a freed workstation that stayed unlocked to save the most unlocks.Medium5GreedyHeap+1No attempts yet10s256 MBJudgeable
Canvas PaintingArrange the canvases in a line and repeatedly split one color group into two so every canvas ends with its own color at the smallest total repaint cost.Medium5GreedyHeapNo attempts yet1s256 MBJudgeable
Minimum Cost RouteFind the cheapest bus fare from city A to city B and print the fare, the city count, and the path, preferring fewer cities and then lexicographic order on ties.Medium5Shortest pathHeapNo attempts yet1s256 MBJudgeable
Technology PlanningPlan the smallest set of technologies covering every goal plus its dependencies, then print the lexicographically smallest valid research order.Medium5Topological sortGraph+2No attempts yet5s512 MBJudgeable
Morning Coffee (Large)Choose one cup per day from day 1 to K so no kind is drunk past its deadline and total satisfaction is largest.Medium5GreedyHeap+1No attempts yet5s512 MBJudgeable
Seat AssignmentAssign seats left to right, each time giving the seat to the still-unseated request with the smallest right endpoint that covers it.Medium5GreedySorting+1No attempts yet0.8s32 MBJudgeable
Train Line ConstructionOn an N by N grid with resident counts and blocked cells, find a 4-direction path between two stations minimizing the sum of cell weights along it.Medium5GraphShortest path+2No attempts yet1s64 MBJudgeable
AssignmentsGiven deadlines and scores for N assignments, pick a subset schedulable within their deadlines to maximize total score.Medium5GreedySorting+2No attempts yet1s256 MBJudgeable
Rain (Small)Given a small grid of island heights, compute the total water trapped after rain, where water escapes to sea at height 0.Medium5GraphBFS+2No attempts yet5s512 MBJudgeable
Cow Dance ShowFind the smallest stage size K so that the total show time, where the next cow starts as soon as a dancer leaves, stays within T_max.Medium5Binary searchSimulation+2No attempts yet2s512 MBJudgeable
Card merge gameEach merge replaces two chosen cards with their sum; after exactly m merges, minimize the total sum of all cards.Medium5GreedyHeap+2No attempts yet1s512 MBJudgeable
Convention IISimulate a single-server queue where queued cows are served by strict priority instead of arrival order, and find the largest start time minus arrival time.Medium5HeapSimulation+1No attempts yet2s512 MBJudgeable
BackdoorFind the shortest travel time from junction 0 to junction N-1 in an undirected weighted graph, where every intermediate junction marked visible is blocked and only the Nexus may be entered.Medium5Shortest pathGraph+2No attempts yet2s512 MBJudgeable
FishmongersAssign each fish to a fishmonger with a weight limit and per-kilogram price so total earnings are maximized.Medium5GreedySorting+2No attempts yet1s512 MBJudgeable
Length of Bundle RopeGiven the sizes of n parcels, repeatedly join two bundles at a time and pay the sum of their sizes, finding the total cost that ties everything into one bundle for the least rope.Medium5GreedyHeap+2No attempts yet2s1024 MBJudgeable
BNKQCustomers arrive over time and each joins the shortest counter queue; find the total time until the last customer finishes being served.Medium5SimulationHeap+2No attempts yet2s512 MBJudgeable
Minimum Number of Conference RoomsGiven N meetings with start and end times, find the minimum number of rooms so that no two overlapping meetings share a room, where a meeting may start exactly when another ends.Medium5SortingGreedy+2No attempts yet2s256 MBJudgeable
Building a Swimming PoolGiven an N by M grid of pillar heights 1 to 9, count the total water trapped on top after water flows off any path to the outside.Medium6HeapBFS+2No attempts yet2s128 MBJudgeable
Jewel ThiefGiven N jewels with weight and value and K bags with weight limits (one jewel per bag), maximize total value stolen using a greedy plus max-heap approach.Medium6GreedyHeap+1No attempts yet1s256 MBJudgeable
Lecture Rooms 2Assign each of N intervals a room number using the minimum number of rooms so overlapping lectures never share a room, touching endpoints allowed.Medium6GreedyHeap+2No attempts yet2s128 MBJudgeable
Graph RelabelingGiven a directed graph as an adjacency matrix, assign each vertex a distinct label from 1 to N respecting all edge order constraints, and output the lexicographically smallest label sequence or -1 if impossible.Medium6Topological sortGreedy+2No attempts yet2s128 MBJudgeable
Making a NumberGiven how many cards exist for each digit 0-9, build the largest possible number using some or all cards so that no two adjacent digits match and no leading zero appears.Medium6GreedyString+1No attempts yet2s128 MBJudgeable
Cup RamenGiven N jobs each taking one time unit with a deadline and a reward, choose which jobs to schedule to maximize total reward earned by finishing before deadlines.Medium6GreedyHeap+1No attempts yet2s256 MBJudgeable
RefuelingFind the minimum number of gas station stops a truck must make, given starting fuel and station positions with fuel amounts, to reach a village on a line.Medium6GreedyHeap+1No attempts yet2s128 MBJudgeable
Nth Largest NumberGiven an N x N matrix where each column is sorted top to bottom, find the Nth largest value among all N^2 entries efficiently.Medium6Binary searchMatrix+1No attempts yet1s12 MBJudgeable
Water FillingGiven a grid of terrain heights, compute the maximum water volume trapped inside using a boundary-based priority-queue flood fill (trapping rain water 2D).Medium6HeapMatrix+1No attempts yet2s128 MBJudgeable
Representative PlayersGiven N classes each with M distinct scores, pick one student per class to minimize the range between the highest and lowest chosen scores.Medium6HeapGreedy+1No attempts yet2s256 MBJudgeable
A Dragon LivesGiven a day-by-day rain forecast on lakes and dry days when the dragon may empty one full lake, decide if overflow can always be avoided.Medium6GreedyHeap+1No attempts yet3s128 MBJudgeable
Pick up sticksGiven a set of on-top-of relations between sticks, output the lexicographically smallest removal order, or IMPOSSIBLE if a cycle exists.Medium6Topological sortGraph+2No attempts yet1s128 MBJudgeable
Dizzy CowsDirect each two-way edge using the lexicographically smallest topological order of the given acyclic one-way edges, or report -1 if a cycle exists.Medium6GraphTopological sort+2No attempts yet1s128 MBJudgeable
Work SchedulingGiven jobs each taking one unit of time with a deadline and a profit, choose a subset to schedule so total profit is maximized.Medium6GreedyHeap+2No attempts yet1s128 MBJudgeable
RoadblocksFind the length of the second-shortest walk from vertex 1 to vertex N in an undirected weighted graph, where walks may repeat edges.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
The Hungary GamesGiven a directed weighted graph, find the second smallest distinct total length among all walks from node 1 to node N, or -1 if fewer than two exist.Medium6Shortest pathGraph+2No attempts yet2s512 MBJudgeable
Shop and ShipGiven an undirected weighted graph, city-specific pencil prices, and a destination D, find the cheapest price plus shipping cost to get a pencil to D.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
Mountain PassageFind the minimum count of steps that touch an elevation above the start height, moving on an n by n grid with height changes limited to 2 per step.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
Swimming PoolGiven an m by n grid of tower heights, find the total volume of water trapped among the towers when the grid is flooded from the outside.Medium6HeapBFS+2No attempts yet1s128 MBJudgeable
Keep the Customer SatisfiedGiven orders with processing times and due dates on a single machine, choose the largest subset that can all finish on time.Medium6GreedySorting+2No attempts yet1s1024 MBJudgeable