Problem link Given two arrays of N integers, pair every value in the first array with one value in the second so that the sum of absolute differences is minimized. Sort both arrays in nondecreasi...
AtCoder. 015 Don't be too close(6)
Problem link Given N positions in a row, for every k from 1 through N, count the ways to choose k positions so that no two chosen positions are adjacent. Print each answer modulo 1,000,000,007. S...
AtCoder. 016 Minimum Coins(3)
Problem link Let dp[x] be the minimum number of coins needed to make total x. Set dp[0] = 0; for every positive amount, the last coin must be one of the three denominations A, B, or C. Therefore, ...
AtCoder. 013 Passing(5)
Problem link For each vertex i, the answer is the shortest distance from vertex 1 to i plus the shortest distance from i to vertex N. The graph is undirected, so the second distance equals the sho...
AtCoder. 009 Three Point Angle(6)
Problem link For each point as a pivot, consider the directions from it to every other point. Any choice of two such directions forms an angle at the pivot, so the answer is the largest smaller an...
AtCoder. 010 Score Sum Queries(2)
Problem link Given each of N students’ classes and scores, answer queries asking for the total scores of Class 1 and Class 2 in the inclusive range [L, R]. Build two prefix-sum arrays, one for ea...
AtCoder. 011 Gravy Jobs(6)
Problem link Each job has a deadline D, duration C, and reward S. Sort the jobs by deadline and process them in that order. Let dp[t] be the maximum reward of a schedule that finishes by time t. ...
AtCoder. 012 Red Painting(4)
Problem link Initially, every cell is white. Each operation either paints a cell red or asks whether two cells are connected using only red cells and four-directional moves. Print Yes if both quer...
AtCoder. 008 AtCounter(4)
Given a string S, count the subsequences equal to atcoder. A subsequence is formed by deleting zero or more characters without changing the order of the remaining characters. Different choices of p...
AtCoder. 007 CP Classes(3)
Problem link Given the ratings of the classes, answer each query with the smallest absolute difference between the query value and any class rating. Sort the ratings once in ascending order, then ...