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 results1,178 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
EvakumMaintain an array with range-add updates and range-sum queries, answering the queries in the order given.Medium5Prefix sumArray+2No attempts yet1.5s256 MBJudgeable
Meditation DisturberEach bird on the left or right chirps on some seconds; remove one bird so the peak absolute value of the running signed sum over M seconds is minimized, and report its index and that value.Medium5Prefix sumImplementation+2No attempts yet2s512 MBJudgeable
5th Job AdvancementOrder n quests and toggle at most k active Arcane Stones to split each quest reward among run lengths, maximizing total collected experience.Medium5SortingPrefix sum+1No attempts yet1s512 MBJudgeable
Adding 1, 2, 3 (9)Count ordered compositions of n into parts 1, 2, and 3 that use at most m terms, and output each count modulo 1,000,000,009.Medium5Dynamic programmingCombinatorics+2No attempts yet1s512 MBJudgeable
DSHS BankPick the branch minimizing the total taxicab distance to all others, breaking ties by smallest branch number.Medium5MathSorting+2No attempts yet2s512 MBJudgeable
Amusement ParkCitizens at various blocks must reach block 0 by taxi (A per block, one rider) or by sharing a bus (B won, up to 40 riders, one pick-up point). Find the minimum total cost.Medium5Dynamic programmingSorting+2No attempts yet1s256 MBJudgeable
Seungbeom CorporationMaintain balances on a company mentor tree while updates add a value to one employee and every employee below them.Medium5TreeDFS+1No attempts yet1s256 MBJudgeable
Area RugCount dirty cells under an s-by-s rug at every placement on an n-by-n grid, then report how many placements cover each possible count.Medium5Prefix sumArray+2No attempts yet2s512 MBJudgeable
Where is the BoundaryGiven m binary strings of length n, cut the line between two prefectures and label each side east or west to minimize mismatches. Report the two prefectures meeting at the best cut, choosing the westernmost one on ties.Medium5Prefix sumArray+2No attempts yet5s512 MBJudgeable
Value of Array BSwap at most one pair of rows or columns in an N by M grid to maximize the sum of all 2 by 2 block sums.Medium5ArrayGreedy+2No attempts yet2s512 MBJudgeable
OperationsMaintain a sparse integer array under point add, point reset, and range sum queries, printing the whole-array sum after each update.Medium5Segment treePrefix sum+2No attempts yet2s512 MBJudgeable
Strength ContestFor each split of a line of fighters into a left and right team, the max of each side fights; count which side wins more splits, or report a tie.Medium5Prefix sumArray+2No attempts yet1s256 MBJudgeable
Stars Falling from the Sky: 1, 2, ..., R-L+1 of ThemMaintain an array where a range update adds 1,2,...,R-L+1 to positions L..R, and point queries ask the current total at one index.Medium5Prefix sumArray+2No attempts yet1s512 MBJudgeable
FLEXDistribute M extra ten-thousand-won units among N days to minimize the sum of squared drops between consecutive daily spends.Medium5Dynamic programmingGreedy+2No attempts yet2s512 MBJudgeable
Sum of DivisorsGiven N up to 10^6 and 10^5 test cases, compute g(N), the sum of the divisor sums f(y) for all y from 1 to N.Medium5MathNumber theory+2No attempts yet1s512 MBJudgeable
Brazilian Popcorn MarathonSplit a row of popcorn bags into at most C contiguous segments, minimizing the maximum segment sum given each competitor eats at most T per second.Medium5Binary searchGreedy+2No attempts yet1.5s512 MBJudgeable
StringsBuild strings by concatenating earlier strings or slicing a substring, then output the sum of ASCII codes of the final string modulo 1e9+7, without materializing the possibly huge string.Medium5Dynamic programmingString+2No attempts yet2s512 MBJudgeable
Summer TripGiven a string of event types, count contiguous substrings of length at least two whose first and last characters are distinct and each appears only once in the substring.Medium5StringTwo pointers+2No attempts yet3s1024 MBJudgeable
Find my FamilyFor each photo, decide whether some arrangement lets Alice (taller than you) stand left of you and Bob (taller than both) stand right of you.Medium5ArrayPrefix sum+2No attempts yet7s512 MBJudgeable
SnowballSnowballs form at each altitude with size 1 and multiply by x each centimeter they descend; find the total size of all snowballs modulo 1e9+7.Medium5MathPrefix sum+2No attempts yet0.5s256 MBJudgeable
Balanced AnimalsFind the smallest integer threshold t that splits the animals by weight into two groups of equal total weight, handling ties at t by pairing them off.Medium5SortingPrefix sum+2No attempts yet1s512 MBJudgeable
BNKQFrom a day of bank teller queue records, find each teller's processed-customer count and busiest one-hour window, then report the top three tellers.Medium5Hash mapSorting+2No attempts yet2s512 MBJudgeable
Stacking Blocks TogetherEach of N students offers a set of distinct block sizes, at most one block per student is used, and we count subsets of students whose chosen blocks sum to exactly H modulo 10007.Medium5Dynamic programmingPrefix sum+2No attempts yet1s256 MBJudgeable
A Really Odd SequenceGiven a sequence of integers, find the maximum sum of a contiguous subarray whose length is odd.Medium5ArrayDynamic programming+2No attempts yet6s512 MBJudgeable
MountainsCount triples x < y < z where the middle mountain y is strictly taller than both mountain x and mountain z.Medium5ArrayCombinatorics+2No attempts yet2s256 MBJudgeable
MerlinGiven n vessels with amounts of elixir, find the minimum number of vessels to empty (and smash) so the remaining vessels can be made equal by redistributing the poured elixir.Medium5GreedyMath+2No attempts yet2s512 MBJudgeable
Finding a Sequence from a Sign MatrixGiven the sign pattern of all subarray sums of a hidden integer sequence, reconstruct one integer sequence (values -10 to 10) that produces the same sign matrix.Medium6Prefix sumMath+2No attempts yet2s128 MBJudgeable
Tree PlantingPlant trees in order and compute the product, modulo 1e9+7, of the sum of distances from each new tree to all previously planted trees.Medium6Segment treePrefix sum+1No attempts yet2s128 MBJudgeable
SoldiersMaintain unit sizes under point updates and answer queries for which unit contains a given soldier serial number using prefix sums.Medium6Segment treeBinary search+2No attempts yet1s256 MBJudgeable
Artist Lee DonghoGiven a black/white grid and a limit on horizontal single-color brush strokes, find the minimum number of cells that end up unpainted or wrongly colored.Medium6Dynamic programmingPrefix sum+2No attempts yet2s128 MBJudgeable
Morning Three and Evening FourGiven N banana weights, choose non-overlapping length-K blocks to move as a C-second group, minimizing total time and then the number of groups used, with output of chosen block positions.Medium6Dynamic programmingPrefix sum+2No attempts yet2s128 MBJudgeable
Sequences of 1 and -1Given M sequences of 1 and -1 of even length N, construct for each one a partner sequence whose elementwise product sums to zero, using at most N distinct partner sequences overall.Medium6CombinatoricsPrefix sum+2No attempts yet2s128 MBJudgeable
Maximum Submatrix SumGiven an N by M integer matrix, find the maximum possible sum over all contiguous rectangular submatrices.Medium6Dynamic programmingMatrix+2No attempts yet2s128 MBJudgeable
Run, RunFind the maximum distance covered in N minutes of running and forced resting under a fatigue cap M, using dynamic programming over run-rest blocks.Medium6Dynamic programmingPrefix sum+1No attempts yet2s128 MBJudgeable
Choosing a Subarray 2Find a contiguous subarray maximizing (sum of elements) times (minimum element), and output that maximum score with the interval bounds.Medium6StackPrefix sum+1No attempts yet2s128 MBJudgeable
Choosing a SubarrayGiven an array, find the contiguous subarray that maximizes the product of its sum and its minimum element.Medium6StackPrefix sum+1No attempts yet2s128 MBJudgeable
Two TowersGiven segment lengths of a cycle of N points, find two points maximizing the shorter of the two circular path distances between them.Medium6Binary searchPrefix sum+1No attempts yet2s128 MBJudgeable
Butcher ShopGiven N meat pieces with weight and price, find the minimum cost so that buying one piece and receiving all strictly cheaper pieces free reaches a target total weight M.Medium6SortingPrefix sum+1No attempts yet2s128 MBJudgeable
Cutting IntervalsGiven N intervals, find cut points A and B minimizing A then B so the total overlapped length inside [A,B] equals exactly K, or output 0 0.Medium6Binary searchPrefix sum+1No attempts yet2s128 MBJudgeable
LieDetect the first parity query in a sequence that becomes inconsistent with earlier ones, using weighted union-find over prefix-sum parities.Medium6Union-findBit manipulation+1No attempts yet2s128 MBJudgeable
Small LocomotivesChoose three disjoint consecutive-car segments (each up to a fixed length) from a train to maximize total passengers carried.Medium6Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Pizza SalesGiven two circular arrays of pizza-slice sizes, count ways to pick a contiguous arc from one pizza, from the other, or one arc from each, summing exactly to K.Medium6Prefix sumHash map+1No attempts yet2s128 MBJudgeable
Car Race MaintenanceGiven a maximum travel range and per-station maintenance times, select a minimum-cost subset of stations so consecutive gaps never exceed the range, and output the chosen stations.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Sanggeun's RobotTrack a moving point's total Manhattan distance to many fixed checkpoints after each move, requiring separate sorted-prefix-sum structures for x and y coordinates updated dynamically.Medium6Prefix sumBinary search+2No attempts yet1s128 MBJudgeable
Salary Management at a Car FactoryGiven a company tree with salary updates that add a value to all subordinates of a node and queries for a single employee's current salary, answer efficiently using an Euler tour and a range-update point-query structure.Medium6TreePrefix sum+1No attempts yet1s256 MBJudgeable
Beautiful MatrixGiven an N x N matrix (N up to 400), find the maximum difference between the main diagonal sum and anti-diagonal sum over all possible square submatrices.Medium6MatrixPrefix sum+1No attempts yet1s128 MBJudgeable
Water TaxiGiven pickup and drop-off points along a line for many passengers picked up by a boat starting at 0 that must end at M, compute the minimum travel distance covering everyone.Medium6GreedyPrefix sum+1No attempts yet1s128 MBJudgeable
Interesting SequenceFor each starting index, find the maximum even-length window whose first half sum and second half sum are both at most S, using binary search and prefix sums.Medium6Binary searchPrefix sum+1No attempts yet1s128 MBJudgeable
Pretty IndentationGiven current and target tab counts per line, find the minimum number of range increment/decrement operations to transform one array into the other, with the constraint that decrements can't push a value below zero.Medium6GreedyArray+1No attempts yet1s128 MBJudgeable
ProgramSimulate marking multiples of several jump values into an array using a difference/counting trick, then answer many range-sum queries with prefix sums.Medium6Prefix sumArray+1No attempts yet2s256 MBJudgeable
Snow White and the DwarfsGiven a sequence of hat colors and range queries, determine for each range whether a majority color exists and identify it.Medium6Binary searchPrefix sum+1No attempts yet1s256 MBJudgeable
Arranging BlocksGiven M unit blocks stacked on cells of an N by N board, find the minimum moves to rearrange them into a rectangle with exactly one block per cell.Medium6Prefix sumBrute force+1No attempts yet1s128 MBJudgeable
Analog DialSimulate M range-sum queries followed by range +1-with-wraparound-to-0 updates on N digit dials, using a data structure that supports both efficiently.Medium6Segment treePrefix sum+1No attempts yet1s256 MBJudgeable
ConfusionCount permutations of 1..N with exactly C inversions, modulo 1e9+7, using DP with prefix sums for the given constraints.Medium6Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Camouflaged CampUsing prefix sums over the grid, find the L x W camp position that satisfies the most given adjacent-area altitude comparison rules, breaking ties by smallest row then column.Medium6Prefix sumSliding window+1No attempts yet1s128 MBJudgeable
Lineland's AirportFind the position of a length-L window along a piecewise-linear terrain profile that minimizes the area above the flat strip that must be excavated.Medium6GeometryBinary search+1No attempts yet2s128 MBJudgeable
Tanks a LotGiven gas stations on a circular track whose fuel exactly covers one lap, list every station and direction from which a full lap can be completed.Medium6Prefix sumGreedy+1No attempts yet1s128 MBJudgeable
Data RecoveryGiven a grid with some unknown cells plus all row and column sums, print each unknown cell's forced value, or -1 if several values fit.Medium6GraphPrefix sum+2No attempts yet5s128 MBJudgeable
Security CompanyPoints lie on a line with travel times between neighbors; starting from point a and visiting every point, minimize the total first-arrival time over all points.Medium6Dynamic programmingGreedy+2No attempts yet2s128 MBJudgeable
Semi-prime H-numbersFor each H-number h, count H-semi-primes up to h, where H-primes are irreducible among numbers of the form 4n+1.Medium6Number theoryMath+2No attempts yet1s128 MBJudgeable
Bulletin BoardGiven up to 100 axis-aligned rectangles on a board, report the uncovered area, the maximum overlap depth, and the area covered at exactly that depth.Medium6GeometrySorting+2No attempts yet1s128 MBJudgeable
Raggedy, RaggedyGiven word widths and a max line length, split the words into lines and minimize the sum of squared unused space on every line except the last.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Think I'll Buy Me a Football TeamGiven a matrix of inter-bank debts, compute the total cash needed to settle all debts and the minimum possible after netting and rerouting payments.Medium6ArrayGraph+2No attempts yet1s128 MBJudgeable
Chop Ahoy! Revisited!Count the ways to split a digit string into consecutive groups whose digit sums are non-decreasing across groups.Medium6Dynamic programmingPrefix sumNo attempts yet1s128 MBJudgeable
Complaint SortGiven a sequence of n values, count the strictly decreasing subsequence triples (i < j < k with a_i > a_j > a_k).Medium6ArrayCombinatorics+2No attempts yet1s256 MBJudgeable
MicrospikesGiven interleaved per-appliance power change records with relative times, reconstruct the total power timeline and count maximal above-threshold intervals of duration 1 to S that start and end.Medium6SimulationSorting+2No attempts yet1s128 MBJudgeable
Digit Sum of a RangeFor each query [a,b] with b up to 10^15, output the sum of all decimal digits of every integer in the range.Medium6MathDynamic programming+2No attempts yet1s128 MBJudgeable
Dividing the LootGiven N item values and P other pirates, choose a set of items for yourself so no other pirate gets more items than you, maximizing your total value.Medium6GreedySorting+2No attempts yet1s128 MBJudgeable
RaisinsSplit an N by M chocolate bar into unit cells by straight cuts; each cut costs the raisins in the piece, and the goal is to minimize the total payment.Medium6Dynamic programmingPrefix sum+2No attempts yet3s128 MBJudgeable
King Jaguar's PyramidPlace an a by b pyramid and an interior c by d chamber on a grid to maximize the sum of base squares minus chamber squares.Medium6Prefix sumBrute force+2No attempts yet1s128 MBJudgeable
Drawing with XOREach XOR call flips a rectangle anchored at the bottom right, so the number of calls equals the count of pixels that differ from the pixel below and the pixel to the right, plus the bottom-right pixel.Medium6ArrayMatrix+2No attempts yet1s512 MBJudgeable
Batch SchedulingSplit the ordered jobs into consecutive batches, each paying a setup time, and minimize the sum of weighted completion times.Medium6Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Light Bulb DecorationGiven a binary string, flip at most one contiguous range so that some contiguous alternating substring becomes as long as possible, and report that length.Medium6ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Card Game is FunAnna may delete arbitrary cards from her sequence and Bruno may trim cards from the top and bottom of his; find the longest common subarray obtainable.Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
The Used BookstoreChoose exactly K of N books to sell, maxing the total where selling t books of one genre adds t(t-1) extra to that genre's group.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Splitting the SnackChoose which of the N-1 cut points to cut so that both people get exactly N/2 pieces, minimizing the total force of the chosen cuts.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Ants ColonyBuild a weighted tree where each new node attaches to an earlier one, then answer distance queries between pairs of nodes.Medium6TreeDFS+2No attempts yet2s128 MBJudgeable
Finding SeatsGiven an R by C grid of free and taken seats, place K people on free seats so the bounding rectangle has the smallest area.Medium6Two pointersBinary search+2No attempts yet1s128 MBJudgeable
Painting the FenceBessie walks along a number line and each segment she covers gains a coat of paint; find the total length covered by at least K coats.Medium6IntervalsSorting+2No attempts yet1s128 MBJudgeable
Painting the FenceBessie walks back and forth along a line, each pass adding a coat; find the total length covered by at least two coats.Medium6Prefix sumSorting+2No attempts yet1s128 MBJudgeable
Balanced Cow BreedsCount the ways to 2-color the parentheses in a string so that each color class, read in order, forms a balanced parenthesis sequence.Medium6Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Nearby CowsOn a tree of N fields with C(i) cows at each field, report for every field the total cows within distance K, where K is at most 20.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Umbrellas for CowsGiven cow positions on a line and a price for each umbrella width, find the cheapest set of umbrellas that covers every cow, allowing overlaps.Medium6Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Above the MedianGiven N cow heights, count contiguous ranges whose defined median (the ceil(K/2)-th smallest) is at least a threshold X.Medium6Prefix sumBinary search+2No attempts yet1s128 MBJudgeable
Mowing the LawnGiven N cows in a row with efficiencies, pick a subset that never includes more than K adjacent cows and maximize the total efficiency.Medium6Dynamic programmingSliding window+2No attempts yet1s128 MBJudgeable
Great Cow GatheringPick a node of a weighted tree with node weights as the gathering point, and minimize the sum of cow count times distance to that node.Medium6TreeDFS+2No attempts yet1s128 MBJudgeable
Secret MessageGiven M binary messages and N binary codewords, count for each codeword how many messages share a prefix relation with it in either direction.Medium6TrieString+2No attempts yet1s128 MBJudgeable
Bulls and CowsCount binary sequences of length N where every pair of bulls has at least K cows between them, modulo 5000011.Medium6Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
CakePartition the sequence of slice lengths into consecutive blocks, bottom to top, so each block's sum is at least the one above, and maximize the number of blocks.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
River CrossingSplit N cows into consecutive groups, each crossing costs M plus the cumulative marginal cost, and add M for every return trip; minimize the total time.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable
Balanced LineupGiven N cow heights and Q ranges, report the difference between the maximum and minimum height within each query range.Medium6Segment treeArray+2No attempts yet1s128 MBJudgeable
Face the Right WayChoose a fixed block size K so that flipping blocks of K consecutive cows turns the whole row forward using the fewest operations, breaking ties by smallest K.Medium6GreedySimulation+2No attempts yet1s128 MBJudgeable
KingGiven weighted inequalities on subarray sums, decide whether some integer sequence satisfies all the bounds; output which phrase tells the answer.Medium6GraphShortest path+2No attempts yet1s128 MBJudgeable
Annoying Painting ToolGiven a target black-and-white grid and a fixed r by c flip rectangle, find the minimum number of flips to reach it, or report impossibility.Medium6GreedySimulation+2No attempts yet1s128 MBJudgeable
Halloween treatsFind the leftmost-shortest consecutive block of neighbours whose sweet total is divisible by c, or report that none exists.Medium6Prefix sumHash map+1No attempts yet1s128 MBJudgeable
Bound FoundFor multiple targets, find the contiguous subarray whose absolute sum is closest to the target, reporting that absolute sum.Medium6Prefix sumSorting+2No attempts yet1s128 MBJudgeable
Bowling for NumbersGiven a row of valued pins, pick up to k non-overlapping blocks of exactly w consecutive pins to maximize the total score.Medium6Dynamic programmingPrefix sumNo attempts yet1s128 MBJudgeable
Primed SubsequencesFind the shortest contiguous subsequence of length at least 2 whose sum is prime, printing the leftmost one if ties exist.Medium6Prefix sumNumber theory+2No attempts yet5s256 MBJudgeable
FlattenDistribute chips between neighboring piles at a cost equal to the chips moved, and find the minimum total transferred to make all piles equal.Medium6Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Dividing the PathPartition the segment [0, L] into consecutive pieces of even length between 2A and 2B so no cut lands strictly inside any cow's interval, and minimize the number of pieces, or report that no partition exists.Medium6Dynamic programmingPrefix sum+2No attempts yet1s128 MBJudgeable