Statistics

Problem Statement for "TransportCounting"

Problem Statement

You are studying public transportation, and you want to know how many buses are going down a particular one-way street every minute. You are driving along the street by car, and counting the buses you meet or overtake. After some time, you stop counting and report the result. In this problem, you may assume that the street is a straight line, and that your car and all of the buses can only go along this line in the same direction.

You will be given an int, speed, giving your speed in meters per minute. You will also be given a int[] positions, specifying how far ahead of you each of the buses is in meters at time 0, and a int[] velocities, specifying the velocities of the buses in meters per minute. The ith element of velocities and the ith element of positions specify the velocity and position of the ith bus, respectively. Finally, an int, time, tells you how many minutes you should count the buses you pass for.

You should return the number of buses you will overtake or meet during time minutes. If you meet one or several buses at the first or at the final moment, count them also.

Definition

Class:
TransportCounting
Method:
countBuses
Parameters:
int, int[], int[], int
Returns:
int
Method signature:
int countBuses(int speed, int[] positions, int[] velocities, int time)
(be sure your method is public)

Constraints

  • positions and velocities will contain the same number of elements.
  • positions will contain between 0 and 50 elements, inclusive.
  • speed and time will both be between 0 and 1000 inclusive.
  • All elements of positions and velocities will be between 0 and 1000, inclusive.

Examples

  1. 100

    {0}

    {0}

    0

    Returns: 1

    Though the duration of your counting is 0, you still can count the first bus.

  2. 5

    {10, 10}

    {0, 1}

    2

    Returns: 1

    There are two buses. The first bus starts 10 meters from you and does not move - so you will reach it in the final moment of your measurement. The second bus starts from the same point as the first one, but goes away from you, covering 1 meter per minute. Thus you won't catch it.

  3. 5

    {10, 10}

    {0, 1}

    3

    Returns: 2

    The same example as before, except time is equal to 3 minutes. This extra minute allows you to meet both buses.

  4. 998

    {1000, 1, 1000}

    {997, 998, 0}

    999

    Returns: 1

  5. 564

    {}

    {}

    607

    Returns: 0

    The street is empty.

  6. 777

    {10,20,30,40,50,60,70,80,90,100, 110,120,130,140,150,160,170,180,190,200, 210,220,230,240,250,260,270,280,290,300, 310,320,330,340,350,360,370,380,390,400, 410,420,430,440,450,460,470,480,490,500}

    {10,20,30,40,50,60,70,80,90,100, 110,120,130,140,150,160,170,180,190,200, 210,220,230,240,250,260,270,280,290,300, 310,320,330,340,350,360,370,380,390,400, 410,420,430,440,450,460,470,480,490,500}

    333

    Returns: 50

  7. 372

    {729,221,185,686,518,560,20,686,390,874,936,451,423,952,500,13,165,896,195}

    {818,683,607,434,297,1,399,506,857,145,703,845,900,187,412,404,110,679,807}

    717

    Returns: 5

  8. 716

    {454,537,44,665,438,475,897,698,828,79,233,101}

    {919,887,572,65,704,223,306,912,979,141,337,117}

    753

    Returns: 8

  9. 203

    {22,219,966,33,860,487,737,312,348,424,693,481,274,394,150,979,962}

    {691,39,124,4,72,850,798,765,126,99,328,623,255,611,120,338,406}

    585

    Returns: 7

  10. 631

    {790,657,142,760,577,263,612,660,847,270,433,486,392,191,595,657,160,252,825,665,617,213,844,902,798}

    {750,790,764,306,454,315,808,86,461,709,770,481,310,29,516,113,541,328,846,709,535,371,564,452,649}

    516

    Returns: 16

  11. 508

    {440,979,712,82,205,565,622,81,171,435,913,161,682,947,918,238,947,534,88,94,149,839,396,572,574,721,537,816,855,195,839,655,96,253,649,622,192}

    {190,370,148,984,885,877,711,437,645,822,767,10,878,147,862,774,375,148,746,833,62,427,568,537,85,996,598,887,818,896,724,90,701,242,988,899,297}

    971

    Returns: 14

  12. 219

    {736,942,913,719,806,787,385,874,482,262,397,40,924,252,228,29,946,963,287,432,26,773,821,879,13,313,854,345,980,714,442,966,986,376,232,644,80,990,144,0,133,414,10,544,266,287,359,276,929,776}

    {236,606,278,150,293,272,526,872,32,892,262,514,421,982,578,350,829,853,385,963,112,869,356,617,373,963,812,606,707,495,606,377,965,3,968,891,809,819,661,923,193,814,38,140,736,599,117,456,746,845}

    83

    Returns: 9

  13. 513

    {437,543,800,293,848,427,844,678,711,403,602,281,73,301,320,367,273,823,914,477,147,736,807,941,133,620,123,184,115,545}

    {966,475,172,205,826,704,714,456,352,822,62,923,363,426,793,501,486,120,672,939,390,717,246,601,923,439,668,965,340,800}

    887

    Returns: 15

  14. 365

    {863,756,557,179,995,680,238,665,8,592,50,114,355,288,173,157,592,12,954,555,567,255,842,20,174,766,776,634,7,52,734,538,982,343,985,226,714,89,321,147,892,596,0,644,157,976,744,318,161}

    {90,598,343,600,777,252,978,665,420,639,537,518,64,38,635,256,833,180,842,14,928,585,819,562,813,315,631,709,165,195,253,950,898,284,642,933,683,703,676,865,423,613,911,241,8,205,205,146,958}

    525

    Returns: 19

  15. 368

    {579,8,55,781,199,180,914,828,357,801,777,943,439,307,810,15,566,782,498,535,396,405,114,192,70,984,840,718,793,687,862,384,664}

    {377,613,967,578,790,312,706,717,940,973,940,390,951,26,424,280,760,241,199,157,536,637,288,261,996,421,152,824,326,975,577,781,70}

    356

    Returns: 11

  16. 531

    {556,28,401,340,725,755,190,865,808,582,274,156,88,699,782,568,852,465,206,582,791,585,212,601,418,366,731,156,966,257,244,33,263,244,452,528,726,701,73,963,570,654,224,877,821,85}

    {768,129,799,661,827,201,314,693,726,526,646,250,775,500,770,610,230,921,476,35,543,689,729,84,94,254,953,57,109,972,226,625,685,258,771,877,42,605,910,589,323,307,923,326,847,540}

    614

    Returns: 20

  17. 29

    {262,90,646,548,432,679,684,24,420,186,953,381,931,410,502,509,476,501,188,999,144,312}

    {308,867,85,386,93,950,786,163,875,737,893,540,945,151,450,582,867,652,819,439,893,119}

    455

    Returns: 0

  18. 549

    {753,952,761,791,211,524,587,64,250,543,754,113,797,620,441,525,523,27,957,823,47,449,458,591,618,944,219,715,987,904,862,230,470,750,559,731,836,895,356,826,650,806,972,20}

    {472,300,54,321,937,57,985,888,961,78,160,554,303,487,109,229,209,115,810,216,369,40,854,152,497,146,432,23,444,381,805,9,333,236,244,126,374,738,134,784,334,202,4,340}

    941

    Returns: 34

  19. 806

    {956,86,156,759,404}

    {229,693,924,116,150}

    705

    Returns: 4

  20. 637

    {190,83,798,108,206,738,278,66,466,376}

    {493,449,314,245,315,809,57,212,543,551}

    728

    Returns: 9

  21. 3

    {242,180,285,720,964,418,574,15,185,251,132,532,614,308,213,225,544,851,206,237,3,439,980,485,647,284,906,628,863,30,943,498,14,679,483,24,444,335}

    {949,522,87,713,405,154,725,177,152,146,393,559,241,983,363,863,215,930,104,12,912,436,215,234,569,506,607,178,693,546,14,465,80,6,854,208,454,191}

    505

    Returns: 0

  22. 444

    {58,696,298,64,132,704,862,456,214,892}

    {507,735,741,526,550,479,671,479,789,392}

    985

    Returns: 1

  23. 212

    {342,427,861,757,77,921,387,538,171,226,617,615,743,26,335,460,24,83,362,873,649,94,711,636,69,280,735,907,646,258,403,35,209,961,706,430,520,44,98,684,36,226,711,359,746,103,847}

    {342,938,737,234,258,117,292,403,52,115,934,714,688,57,511,561,858,26,900,18,715,221,806,147,936,770,596,13,162,713,117,52,413,461,810,90,10,214,58,838,180,565,494,669,650,295,937}

    671

    Returns: 15

  24. 797

    {208,974,790,784,68,175,520,388,364,900,822,341,113,513,953,873,102,410,648,800,595,667,61,559,805,210,815,849,983,592,327,159,546,731,551,396,831,918}

    {346,766,855,172,462,532,788,74,27,790,201,140,247,663,339,679,285,488,897,845,258,987,671,398,189,36,355,609,308,649,806,603,640,720,80,275,429,948}

    975

    Returns: 32

  25. 590

    {74,757,92,722,505,69,397,933}

    {549,584,697,653,326,365,820,568}

    759

    Returns: 5

  26. 827

    {145,274,858,709,649,684,783,939,392,350}

    {384,515,445,935,737,734,575,156,509,426}

    974

    Returns: 9

  27. 234

    {597,280,699,897,348,826,531,360,40,265,574,72,699}

    {894,974,407,164,915,52,761,22,923,631,704,435,386}

    78

    Returns: 3

  28. 571

    {129,892,611,455,419,394,260,334,219,918,417,281,191,849,804,227,330,173,924,951,574,977,804,447,602,624,791,954,222,476,876,99,563,913,797,513,680,56,962,949}

    {174,550,147,572,801,914,950,675,880,816,977,191,0,400,149,475,777,317,771,134,973,604,221,920,446,21,686,773,631,919,143,406,137,264,929,757,864,951,916,848}

    469

    Returns: 17

  29. 405

    {873,139,469,463,196,827,653,196,573,929,835,864,784,253,660,135,236,856,582,256,65,117,729,96,811,940,382,656,782,991,7}

    {623,67,246,474,791,941,615,183,408,616,127,387,472,14,685,179,301,126,335,350,371,592,262,548,484,977,786,761,427,382,953}

    931

    Returns: 14

  30. 575

    {716,977,625,583,64,628,525,454,242,227,6,609,427,798,547,55,813,421,113,14,477,587,157,201,478,900,160,42}

    {766,259,772,635,857,566,485,782,810,950,500,504,667,184,240,435,672,518,498,331,257,858,356,37,948,137,201,140}

    174

    Returns: 17

  31. 711

    {457,713,470,509,945,604,100,966,747,65,430,227,124,514,896,271,135,999,41,889,621,946,432,14,104,204,15,12,173,796,952,810,161,909,979,668,595,403,996,523,871,860,787,692,456,391,752,519,987,923}

    {860,22,879,628,689,445,158,298,448,233,633,886,622,137,961,297,729,889,234,303,36,578,607,290,937,30,103,655,947,194,955,527,65,157,39,181,5,972,226,259,210,435,202,20,664,848,947,426,494,166}

    502

    Returns: 38

  32. 577

    {656,484,750,52,443,851,505,137,451,191,864,201,246,435,740,343,454,419,309,869,125,537,704,886,317,649,621,592,954,211,353,776,412,36,249,39,842,148,163}

    {120,479,718,250,605,200,40,856,413,967,615,123,39,671,172,281,862,851,306,179,382,844,432,142,402,193,786,17,863,938,849,46,310,418,620,952,544,469,284}

    68

    Returns: 24

  33. 430

    {451,895,709,40,72}

    {134,824,776,638,582}

    161

    Returns: 1

  34. 801

    {248,547,657,920,555,539,169,525,115,363,489,44,208,855,855,623,703,6,808,482,505,56,722,234,190,173,687,732,948,708,185,576,536,742,937,537,991}

    {188,201,758,552,879,699,38,650,591,969,32,111,955,384,310,275,470,914,4,292,500,888,141,257,308,563,768,974,498,822,325,898,350,678,68,573,338}

    950

    Returns: 29

  35. 923

    {379,346,461,461,645,647,451,170,323,851,391,946,560,291,783,520,738,169,470,451,571,486,414,449,918,889,379,134,75,499,523,124,695,531,764,683,915,655,838,622,360,186}

    {932,109,35,341,57,367,763,227,3,451,21,526,96,451,483,561,93,942,38,881,291,912,873,46,640,864,420,181,652,221,114,824,761,668,64,265,253,132,764,923,783,650}

    970

    Returns: 39

  36. 867

    {470,368,488,146,383,661,841,593,498,994,0,122}

    {576,916,236,756,212,615,679,623,68,866,388,874}

    106

    Returns: 9

  37. 119

    {199,561,984,30,521,596,43,734,221,455,989,392,89,398,270,40,438,274,195,479}

    {385,116,185,920,244,104,838,969,613,745,530,991,580,238,545,428,448,338,702,439}

    113

    Returns: 1

  38. 38

    {288,167,531,753,630}

    {939,416,536,216,74}

    129

    Returns: 0

  39. 206

    {362,740,466,105,344,439,602,582,870,65,462,538,3,596,394,354,983,10,929,536,374,876,159,969,739,895,628,448,931,862,830,937,461,985,286,191,356,546,373,165,890,679,51,76,478,171,884}

    {734,140,491,422,704,522,268,642,720,571,890,662,118,863,118,541,669,741,675,458,747,73,402,849,41,464,20,460,276,842,741,958,40,100,304,910,325,689,526,875,504,434,918,640,859,807,641}

    930

    Returns: 8

  40. 46

    {983,378,627,203,338,575,15,717,369,78,163,267,99,523,105,869,611,84,378,890,466,646,875,132,366,407,183,441,941,647,926,438,446,912,571,529,838,201,742}

    {529,360,548,599,452,582,155,158,146,836,432,724,850,679,772,51,643,939,488,243,448,211,211,860,558,593,766,282,30,196,865,874,337,900,85,467,370,736,671}

    405

    Returns: 1

  41. 50

    {336,364,166,318,249,347,389,400,18,412}

    {465,267,544,999,948,451,440,961,417,116}

    961

    Returns: 0

  42. 884

    {729,754,914,586,824,969,280,173,279,158,17,621,533,983,518,438,196,723,146,714,645,269,671,101,961,980}

    {776,618,144,80,553,675,197,310,857,670,867,507,957,175,222,392,996,36,887,920,749,101,986,249,73,84}

    47

    Returns: 21

  43. 336

    {94,88,951,553,283,658,667,981,683,158,441,570,104,715,347,600,55,995,675,788,673,43,789,16,606,272,993,327,649,260,198,314,716}

    {867,855,953,535,682,26,191,59,635,814,489,172,163,300,747,859,585,299,283,326,93,402,254,629,794,537,554,751,719,300,80,602,969}

    123

    Returns: 13

  44. 75

    {973,614,695,88,392,624,400,455,775,709,304,151,512,496,108,710,486,675,774,773,870,259,729,400,930,602,722,109,629,820,736,714,662,913,50,347,209,435,47,968,532,311,562,235,1000}

    {17,558,913,288,248,486,88,379,259,394,797,498,428,463,975,689,660,272,263,216,416,402,962,557,751,286,638,511,202,395,429,334,266,506,85,485,118,276,349,981,650,648,429,506,628}

    180

    Returns: 1

  45. 539

    {135,799,160,485,108,887,150,719,936}

    {606,191,768,113,562,893,841,639,7}

    711

    Returns: 3

  46. 978

    {74,373,566,222,485,778,697,685,101,556,102,445,940,138,59,814,781,3,851,428,983,465,470,990,368,928,940,171,975,963,672,950,33,370,650,137}

    {958,529,580,192,708,498,460,427,472,411,693,335,578,40,924,308,286,50,85,287,1000,723,211,951,182,644,59,139,596,243,746,250,297,85,681,725}

    157

    Returns: 35

  47. 625

    {146,679,275,381,632,81,649,13,748,722,276,554,61,919,680,850,250,850,206,396,448,653,329,661,602,755,817,771,48,43}

    {119,717,704,257,489,518,412,195,420,537,381,307,308,500,611,542,430,489,524,427,592,838,469,570,581,655,886,329,143,488}

    399

    Returns: 25

  48. 921

    {256,122,69,560,521,442,861,699,615,425,868,528,906,732,177,608,119,29,237,711,270,508,594,974,570,166,455,565,594,259,134,989,489,87,751}

    {888,680,70,90,872,669,207,306,333,606,786,274,191,887,381,957,713,87,427,335,840,266,542,420,348,940,886,195,98,513,446,857,992,505,348}

    338

    Returns: 32

  49. 907

    {610,557,144,100,244,23,942,943,274,482,353,282,689,371,692,435,834,705,188,749,403,639,995,956,909,109}

    {853,273,286,700,777,272,210,922,899,338,959,538,181,989,235,211,514,301,808,856,661,592,161,401,468,543}

    789

    Returns: 23

  50. 313

    {3,570,237,627,634,384,782,205,413,751,815,999,782,50,465,351,689,541,542}

    {558,13,706,783,20,968,817,501,178,123,43,947,453,338,353,609,639,181,939}

    706

    Returns: 6

  51. 916

    {772,996,25,959,994,553,860,366,31,297,987,420,488,507,577,306,792,324,548,359,821,961,44,506,107,97,865,995,163,49,513,48,734,443,574,128,539,786,725,357,657,72,514,685,32,112,483}

    {982,493,229,235,312,166,439,907,667,91,971,93,894,3,439,667,717,457,872,22,155,918,764,924,585,533,481,928,546,470,429,797,752,947,633,204,716,795,555,437,468,912,610,680,234,835,527}

    423

    Returns: 41

  52. 39

    {201,881,592,626,327,501,151,393,850,88,472,153,320,808,714,766,690,764,894,298,180,429,800,362,210,975,235,971,60,122,897,879,331,979,499,257,414,37,142,332,228,289,97,432,636,933,286,695,907}

    {435,398,653,603,202,404,44,532,796,830,588,594,121,843,490,706,731,797,714,144,601,521,63,29,322,485,607,529,178,893,822,454,355,63,314,140,875,398,976,16,811,253,545,961,955,212,328,528,442}

    998

    Returns: 2

  53. 978

    {410,329,696,828,276}

    {335,669,621,778,573}

    820

    Returns: 5

  54. 98

    {776,709,902}

    {468,757,554}

    373

    Returns: 0

  55. 433

    {766,25,539,176,45,310,426,149,742,545}

    {283,628,862,90,581,263,522,90,302,657}

    123

    Returns: 5

  56. 710

    {596,587,745,518,25,276,660,632,885,974,540,249,807,690,440}

    {96,142,115,924,279,399,838,454,933,771,371,729,423,574,621}

    56

    Returns: 10

  57. 5

    {0,0,0}

    {4,5,6}

    10

    Returns: 3

  58. 5

    { 0, 0, 0 }

    { 4, 5, 6 }

    10

    Returns: 3

  59. 5

    { 0 }

    { 10 }

    10

    Returns: 1

  60. 1

    { 0 }

    { 2 }

    2

    Returns: 1

  61. 1

    { 0 }

    { 2 }

    1

    Returns: 1

  62. 1

    { 0 }

    { 2 }

    5

    Returns: 1

  63. 15

    { 45 }

    { 20 }

    6

    Returns: 0

  64. 5

    { 0, 0, 0 }

    { 2, 5, 20 }

    5

    Returns: 3

  65. 1

    { 1 }

    { 1 }

    1

    Returns: 0

  66. 1

    { 0 }

    { 4 }

    1

    Returns: 1

  67. 5

    { 0, 0, 0 }

    { 20, 20, 20 }

    1

    Returns: 3

  68. 1

    { 5 }

    { 5 }

    11

    Returns: 0

  69. 5

    { 10, 10 }

    { 0, 1 }

    2

    Returns: 1

  70. 2

    { 1 }

    { 1 }

    1

    Returns: 1

  71. 1

    { 2 }

    { 1 }

    10

    Returns: 0


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: