Statistics

Problem Statement for "TrickyInequality"

Problem Statement

This problem statement contains superscripts and/or subscripts. These may not display properly outside the applet.

There are m positive integer variables: x1, x2, ..., xm. We do not know their exact values, we only know some inequalities they satisfy:
  • The sum of all our variables is at most s. Formally: x1 + x2 + ... + xm <= s.
  • Each of the first n variables is less than or equal to t. Formally: for each i such that 1 <= i <= n we have xi <= t.
You are given the long s and the ints t, n, and m. Compute and return the number of solutions to the above inequalities, modulo 1,000,000,007.

Definition

Class:
TrickyInequality
Method:
countSolutions
Parameters:
long, int, int, int
Returns:
int
Method signature:
int countSolutions(long s, int t, int n, int m)
(be sure your method is public)

Constraints

  • m will be between 1 and 10^9, inclusive.
  • n will be between max(1,m-100) and m, inclusive.
  • t will be between 1 and 10^5, inclusive.
  • s will be between n*t and 10^18, inclusive.

Examples

  1. 3

    1

    1

    2

    Returns: 2

    In this test case we have two variables, and we know that their sum is at most 3 and that the first variable is at most 1. Formally, we have x1 + x2 <= 3 and x1 <= 1. There are only two solutions in positive integers: (1,1) and (1,2).

  2. 5

    2

    2

    3

    Returns: 8

    Here we are given the following inequalities: x1 + x2 + x3 <= 5 x1 <= 2 x2 <= 2 There are 8 solutions: (1,1,1), (1,1,2), (1,1,3), (1,2,1), (1,2,2), (2,1,1), (2,1,2) and (2,2,1).

  3. 30

    1

    1

    10

    Returns: 10015005

    From the constraints we know that x1 must be 1. Therefore the sum of the nine positive integers x2 through x10 has to be at most 29. It's not hard to find that the answer is the binomial coefficient C(29,9) = 10015005.

  4. 2000

    20

    100

    200

    Returns: 35422605

  5. 999999999999999999

    100000

    999999900

    1000000000

    Returns: 90919453

  6. 105721

    64

    33

    37

    Returns: 754903408

  7. 199606

    86

    9

    77

    Returns: 168458140

  8. 136390

    46

    36

    58

    Returns: 119923226

  9. 55652

    55

    71

    85

    Returns: 626482586

  10. 145629

    70

    31

    60

    Returns: 578609714

  11. 80895

    51

    22

    46

    Returns: 618063228

  12. 119027

    51

    42

    89

    Returns: 619580162

  13. 179253

    60

    3

    86

    Returns: 862177304

  14. 936353860

    2567

    4080

    4128

    Returns: 994409629

  15. 499262409

    2921

    7366

    7455

    Returns: 954667004

  16. 821866211

    1855

    6374

    6406

    Returns: 701421003

  17. 542338886

    1799

    6290

    6315

    Returns: 90129548

  18. 212290927

    1974

    5152

    5193

    Returns: 646281596

  19. 927503294

    2728

    6947

    6974

    Returns: 310873199

  20. 562509916

    1251

    3390

    3392

    Returns: 867963158

  21. 445405970

    1381

    5327

    5338

    Returns: 457279940

  22. 822443751041689486

    89990

    840084932

    840085005

    Returns: 582496398

  23. 739208549591790864

    45308

    881683449

    881683453

    Returns: 568281006

  24. 537236399226899931

    35861

    612961921

    612961978

    Returns: 670452216

  25. 314476328358855739

    63810

    938081821

    938081863

    Returns: 601268500

  26. 603481587169811383

    82514

    455427928

    455427965

    Returns: 567654130

  27. 183168589723451860

    80659

    950992302

    950992313

    Returns: 367813229

  28. 850655409765034582

    81209

    754094342

    754094428

    Returns: 501637702

  29. 10411406421488205

    43074

    345576398

    345576469

    Returns: 782878466

  30. 884057837920698216

    92759

    949625116

    949625216

    Returns: 693753718

  31. 407682383075488511

    91264

    902815697

    902815796

    Returns: 533583724

  32. 78765808655104121

    94182

    927929972

    927930068

    Returns: 727041581

  33. 374154320325198739

    98263

    953078799

    953078894

    Returns: 61260449

  34. 289111266817153309

    91435

    990097892

    990097986

    Returns: 887060752

  35. 801935492095650470

    90467

    933140054

    933140150

    Returns: 23667027

  36. 999999999999999999

    100000

    1000000000

    1000000000

    Returns: 297793005

  37. 801935492095650470

    90467

    933140150

    933140150

    Returns: 106285029


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: