Vasiljko's blog

By Vasiljko, history, 8 years ago, In English

Given string S of N (N<=100 000) characters (each character is digit). Also given, L and R (L <= R <= 109 ). Find maximum sum that is possible to obtain cutting the string in such a way that every part has value <=R and >=L.

Input: N L R S

Test case:
8 13 997
81196054

Output: 1825

Explanation: These are all possible cuts. Last cut is best
1. 81|19|60|54
2. 81|196|054
3. 811|96|054
4. 811|960|54

  • Vote: I like it
  • +10
  • Vote: I do not like it

»
8 years ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

dp[i] = maximum answer on prefix. Every iteration, try all numbers with digits [i+1 ... r) and update dp[r]. r can't go far from i.