Skip to content
We areTOP 1%

Kuriyama Mirai's Stones

EasyRating 1200CodeforcesPrefix Sum
Solve on Codeforces(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Build one prefix-sum array over the original costs and another over a sorted copy; the query type selects the array. Sums exceed 32 bits, so use long long.

More in Prefix Sum

Prefix Sum questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Running Sum of 1d ArrayLeetCodeEasy Solve Running Sum of 1d Array on LeetCode (opens in a new tab)
2Find Pivot IndexLeetCodeEasy Solve Find Pivot Index on LeetCode (opens in a new tab)
3Range Sum Query - ImmutableLeetCodeEasy Solve Range Sum Query - Immutable on LeetCode (opens in a new tab)
4Odd QueriesCodeforcesEasy 900Solve Odd Queries on Codeforces (opens in a new tab)
5Distinct SplitCodeforcesEasy 1000Solve Distinct Split on Codeforces (opens in a new tab)
6Ilya and QueriesCodeforcesEasy 1100Solve Ilya and Queries on Codeforces (opens in a new tab)
7Sereja and SuffixesCodeforcesEasy 1100Solve Sereja and Suffixes on Codeforces (opens in a new tab)
8Kuriyama Mirai's StonesCodeforcesEasy 1200Solve Kuriyama Mirai's Stones on Codeforces (opens in a new tab)
9Range Sum Query 2D - ImmutableLeetCodeMedium Solve Range Sum Query 2D - Immutable on LeetCode (opens in a new tab)
10Product of Array Except SelfLeetCodeMedium Solve Product of Array Except Self on LeetCode (opens in a new tab)
11Subarray Sum Equals KLeetCodeMedium Solve Subarray Sum Equals K on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account