Statistics

Problem Statement for "ApplePie"

Problem Statement

You have decided to make an apple pie. For this you need howMany apples. You are going to gather the apples from your garden. An apple can only be gathered once it falls on the ground. Unfortunately, you discovered that some apples are going to fall on your neighbors' garden, because your tree has grown out of your garden's bounds.

Given the exact coordinates where each apple falls (x[i] and y[i] are the coordinates for the i-th apple), and the exact day when it will fall (day[i] is the day for the i-th apple), determine the day on which you will have all the apples you need to make your pie. If it's impossible to gather howMany apples, return -1.

Your garden is a rectangle with corners (0,0), (0,100), (100,100) and (100,0). If an apple falls within, or on the border of your garden, you can gather it. Apples that fall outside your garden belong to your neighbors.

Definition

Class:
ApplePie
Method:
getApples
Parameters:
int[], int[], int[], int
Returns:
int
Method signature:
int getApples(int[] x, int[] y, int[] day, int howMany)
(be sure your method is public)

Notes

  • Don't worry that your apples fall during the whole year. You will be able to find them in snow.

Constraints

  • x, y and day will all contain the same number of elements, between 1 and 50, inclusive.
  • Each element of x and y will be between -1000 and 1000, inclusive.
  • Each element of day will be between 1 and 365, inclusive.
  • Elements of day will be in non-descending order (that is, day[i] will be less than or equal to day[i+1] for all i).
  • howMany will be between 1 and the number of elements in x, inclusive.

Examples

  1. {0,50,600,50}

    {0,-400,100,40}

    {1,4,6,8}

    2

    Returns: 8

    You can take the apples that fall on days 1 and 8.

  2. {14,-958,38,32,69}

    {48,485,58,76,75}

    {1,2,3,6,15}

    3

    Returns: 6

  3. {783,63,86,632,-13}

    {279,120,-17,210,-45}

    {1,3,9,11,17}

    1

    Returns: -1

  4. {368,912,-76,14,78,191,-687,-501,-628,-49}

    {-949,442,992,19,78,233,616,741,296,135}

    {1,6,12,19,26,32,34,35,37,43}

    2

    Returns: 26

  5. {80,22,50,76,-871,-17,-685,112,-27,150}

    {94,-39,8,22,-249,-34,746,35,-41,-14}

    {1,5,13,14,16,17,18,27,29,31}

    3

    Returns: 14

  6. {224,-49,505,-1000,666,-462,887,-540,-109,-739}

    {-787,144,-339,-689,3,-721,-245,876,25,-785}

    {1,1,3,8,14,22,28,32,40,46}

    3

    Returns: -1

  7. {303,108,129,614,114,215,927,-259,-478,-135}

    {698,112,-32,-370,164,576,-907,-52,365,-59}

    {1,5,12,14,15,19,19,24,26,30}

    2

    Returns: -1

  8. {61,185,60,172,172,535,621,227,-544,814}

    {34,160,218,138,67,-469,-403,-144,-706,-230}

    {1,1,2,3,10,11,11,13,22,24}

    1

    Returns: 1

  9. {412,-25,-819,0,87,-288,-15,-57,147,-40}

    {822,-83,-383,125,-363,-232,7,31,150,-38}

    {1,10,15,22,27,35,36,36,45,50}

    1

    Returns: -1

  10. {696,-124,39,-433,-8,898,-454,216,-985,195}

    {-688,20,-58,-182,-35,-375,-331,155,316,179}

    {1,2,11,11,11,12,20,21,29,32}

    1

    Returns: -1

  11. {1,-976,116,-613,22,249,987,95,-565,-98,-47,49,144,-422,-678,549,69,-43,-26,66}

    {39,-263,56,-23,57,-51,-290,-6,686,760,144,110,24,823,-271,328,16,-37,-9,16}

    {1,7,7,7,9,18,20,20,23,26,27,33,41,44,46,46,53,55,64,66}

    4

    Returns: 66

  12. {660,41,250,886,49,14,61,134,62,922,101,54,108,92,105,54,-22,29,-186,148}

    {349,-26,67,605,80,-28,-439,128,-43,-678,90,-2,39,-50,52,138,14,914,953,500}

    {1,5,8,9,9,13,13,19,26,26,27,36,44,45,45,52,61,64,73,79}

    3

    Returns: -1

  13. {20,65,558,159,-18,60,678,-921,-29,947,360,-212,7,18,-50,13,94,-396,101,40}

    {85,-19,796,10,14,702,-163,-510,9,-6,690,-448,8,-42,76,40,81,-497,-28,102}

    {1,2,6,14,23,25,25,33,36,43,43,46,49,58,64,73,81,86,93,96}

    6

    Returns: -1

  14. {147,40,-244,-398,89,143,-719,903,86,-33,8,-13,-405,-191,48,-367,522,-11,53,129}

    {133,11,-591,136,100,60,450,213,102,-6,58,49,-652,-216,7,543,-948,15,100,39}

    {1,5,8,16,19,22,26,29,36,37,42,46,50,50,56,61,70,78,78,78}

    4

    Returns: 56

  15. {51,77,-325,-100,235,-79,168,-563,114,21,-133,-128,330,-72,184,-130,-136,113,101,-33}

    {94,-137,-791,-50,-142,45,-680,-595,223,-13,-2,943,-327,-287,-853,64,141,2,-20,18}

    {1,2,10,11,11,18,25,32,33,42,51,55,60,60,66,71,80,86,89,94}

    4

    Returns: -1

  16. {153,-53,64,24,18,10,-165,-671,-928,-125,24,38,-421,95,-38,14,188,-932,662,-47}

    {13,94,-664,-37,-101,92,-740,-850,-858,-96,-91,-907,-637,124,42,242,-116,-449,435,-824}

    {1,10,10,14,15,16,25,29,34,37,38,41,44,47,53,53,56,65,68,68}

    6

    Returns: -1

  17. {-972,-657,-103,617,4,-19,9,65,67,-971,-257,677,-149,46,-98,158,-24,-514,19,253}

    {676,-378,147,194,157,78,206,-96,241,877,-427,522,228,-111,192,41,94,-332,197,329}

    {1,3,3,10,11,12,15,19,21,24,33,33,33,42,48,57,62,63,66,68}

    2

    Returns: -1

  18. {90,-495,-80,190,45,-36,594,-846,-11,-148,84,80,-656,533,-613,61,-513,-746,-19,158}

    {180,-901,-72,198,-81,94,-446,-252,130,159,121,-30,-74,-80,508,82,571,-341,191,114}

    {1,7,14,16,22,25,34,35,44,44,53,58,60,61,66,72,74,81,84,86}

    3

    Returns: -1

  19. {152,-754,218,-654,893,243,-861,213,133,-215,98,365,908,-952,96,15,173,-28,5,-557}

    {216,-673,-49,-535,923,146,67,-52,1,988,-41,929,-767,172,-726,136,64,34,99,-374}

    {1,4,9,15,18,21,27,29,32,37,46,54,57,59,62,66,67,72,81,87}

    5

    Returns: -1

  20. {-17,-991,74,-22,-46,-582,-45,643,19,44,-2,-607,28,-58,-529,-935,-299,50,-10,928,-41,-278,-64,-644,970,946,147,-13,944,109,47,6,-46,60,-30,931,145,727,130,-410,-165,88,-50,-3,-690,43,15,-432,752,542}

    {118,-715,112,-12,64,-767,146,-272,19,18,-32,381,74,12,170,576,-501,60,19,630,24,694,-3,622,453,-136,68,-166,-11,11,-625,125,114,116,-6,982,44,-480,-734,-679,-489,105,119,132,-300,34,-25,-244,-79,-318}

    {1,7,10,18,18,18,21,26,35,42,43,43,48,49,53,57,64,65,68,70,70,78,80,84,88,96,101,109,111,118,126,133,136,139,144,147,150,150,159,164,171,173,178,183,186,188,189,189,192,198}

    1

    Returns: 35

  21. {-13,124,-607,57,-221,85,64,177,-23,90,-237,-348,-701,59,686,-10,573,31,718,63,11,-542,30,-160,577,68,765,1,272,134,97,127,108,-921,532,35,-279,147,112,68,-164,43,138,-308,-49,66,-45,-37,-475,-57}

    {26,108,-41,7,-648,-908,126,-884,123,64,-168,83,-745,71,162,123,176,150,949,68,68,-659,-915,942,33,113,-239,25,-787,18,4,-49,-24,718,-879,-35,367,134,-5,-6,982,-42,13,-764,80,73,111,36,-995,529}

    {1,8,14,14,16,24,26,35,44,51,53,61,65,67,75,77,80,88,89,97,104,104,110,115,120,126,126,131,138,141,143,152,154,155,156,160,169,173,178,186,189,196,202,209,210,217,226,231,236,238}

    8

    Returns: 217

  22. {46,138,-420,-528,109,508,108,136,52,-38,-941,98,-995,-151,-269,133,-868,141,146,53,-9,500,987,845,-17,-1,51,-13,149,14,75,79,-50,117,552,59,-28,23,-663,-795,-15,954,-724,-32,-640,-436,-50,-951,87,742}

    {-11,78,242,-707,51,-547,43,102,-46,-9,593,79,277,600,-965,-49,-500,18,-26,17,92,-609,-652,-273,-22,125,60,96,60,-439,74,64,75,0,-86,127,9,137,-278,-801,-23,872,-796,13,471,797,-36,971,-45,51}

    {1,9,11,12,16,23,23,23,31,40,43,49,49,53,53,53,62,62,64,66,75,79,81,83,88,88,96,98,106,107,112,117,126,133,139,144,150,158,165,171,180,181,183,192,197,202,211,217,222,224}

    15

    Returns: -1

  23. {833,8,-31,54,87,113,-35,22,790,-475,952,-191,16,871,14,-878,746,68,-142,40,-7,84,-18,120,-407,-196,87,-22,-50,-754,-827,-660,132,53,-13,68,805,-48,-929,151,88,-10,960,104,-25,-461,-44,196,-8,137}

    {601,21,70,-3,-10,121,4,127,591,-361,-408,321,107,902,84,612,556,100,545,38,136,34,79,131,834,100,5,145,-705,110,-846,454,69,0,92,109,769,96,984,-84,70,135,-764,-24,15,-583,121,-969,-17,18}

    {1,2,9,15,24,33,40,40,47,50,51,60,67,69,76,77,78,85,85,94,101,101,103,109,113,122,126,131,140,145,146,149,155,156,165,173,175,181,189,198,207,216,216,224,227,234,235,240,244,245}

    16

    Returns: -1

  24. {110,426,65,-712,22,56,21,-717,-260,134,113,12,-546,31,-46,-989,94,14,23,113,101,-516,69,914,-740,144,-27,75,926,25,708,-525,65,9,-680,87,66,113,35,-45,-271,149,-831,183,-497,-29,78,123,-14,150}

    {35,-246,50,763,59,73,98,-516,150,56,107,58,-651,-29,118,-774,59,-17,-472,94,-12,-186,92,-876,554,121,26,-695,-835,62,637,902,48,14,664,108,137,131,-11,101,486,97,-351,392,-594,126,128,-24,-42,107}

    {1,8,17,22,22,25,27,35,35,37,42,45,53,61,69,77,80,82,84,87,92,96,97,104,104,108,113,115,119,126,129,137,141,145,148,155,155,160,167,167,167,169,174,182,185,188,194,200,207,207}

    2

    Returns: 22

  25. {150,-482,-806,150,-817,145,-98,-147,103,84,96,8,-87,858,-634,-75,-618,224,71,179,-11,-493,85,-150,476,-875,112,-43,-832,-148,315,88,245,198,-76,-725,-481,395,-66,17,-522,660,248,210,517,71,-864,456,45,-150}

    {-63,889,-659,-23,-592,70,161,19,178,570,95,121,9,645,816,220,478,128,83,-775,199,606,885,-35,503,-41,186,190,-586,53,30,12,-40,17,-676,35,-255,283,110,164,-148,680,107,203,-119,70,837,-642,-53,77}

    {1,2,11,20,21,27,35,41,49,53,61,65,71,74,79,88,92,93,97,98,98,101,101,106,111,115,122,123,129,138,138,141,141,150,154,157,162,166,175,180,180,188,189,196,199,208,216,223,223,225}

    1

    Returns: 61

  26. {-401,15,203,46,-13,210,577,-8,57,-292,620,479,224,469,36,338,161,133,-353,31,68,175,874,-181,-382,1,-990,-134,149,244,-330,228,-751,-121,503,-110,61,-7,-680,150,232,19,77,205,127,-65,-120,-268,249,201}

    {435,36,199,-147,-33,702,424,-111,-62,92,-705,-205,-47,-456,45,-582,226,211,55,8,183,-78,700,46,-246,127,-276,-555,-14,63,227,27,-374,-48,-189,38,126,185,136,56,-17,-146,-106,86,117,162,108,-29,68,199}

    {1,6,9,11,17,22,31,33,37,40,48,49,58,67,75,79,79,87,90,94,95,100,104,111,117,118,123,129,137,140,140,140,148,152,154,158,159,162,170,177,183,192,200,208,216,222,224,224,228,235}

    12

    Returns: -1

  27. {975,246,762,-445,697,-55,114,93,46,12,-23,-132,56,-40,569,137,-242,416,342,523,-139,-110,713,975,-80,202,508,-489,-865,117,81,115,204,676,123,-85,222,410,286,-842,43,-115,-665,100,-44,904,365,272,320,-136}

    {-649,237,790,-936,930,48,-71,172,5,186,111,237,50,46,155,-5,-611,574,-835,232,-77,174,-792,625,23,91,529,-694,994,-96,247,-13,-640,917,188,66,245,583,-160,649,335,248,128,148,-829,-717,67,-882,414,246}

    {1,5,5,6,10,14,20,22,29,34,36,36,37,42,50,55,56,60,68,73,74,80,80,84,84,89,97,97,103,108,108,115,124,126,126,129,135,141,148,151,155,164,167,174,181,184,189,197,204,209}

    5

    Returns: -1

  28. {145,130,52,-738,902,-58,668,222,560,-20,-92,5,60,182,-17,128,252,954,199,-825,291,-784,-140,134,434,-885,66,175,-461,770,692,70,2,102,31,-105,288,860,-120,-153,-161,460,148,189,-58,-1000,67,246,18,63}

    {197,-82,155,-80,403,8,-408,-740,56,-312,-37,-18,214,115,-94,-6,-876,-20,-97,680,385,65,96,-37,123,-496,67,-140,121,507,-221,202,-97,76,-97,-72,885,-462,169,-502,227,114,194,-100,219,-948,117,201,-6,322}

    {1,3,7,7,11,18,21,24,33,36,44,51,52,55,56,60,64,69,73,77,79,82,85,91,92,93,97,97,105,114,122,128,131,136,144,153,155,158,160,163,169,169,169,178,183,187,191,192,193,193}

    1

    Returns: 97

  29. {-90,126,881,-247,227,27,-278,-26,135,203,83,833,-131,230,228,114,366,416,259,167,-459,-119,-895,-370,184,-214,248,-273,222,24,87,-91,-27,-75,-95,-652,-686,-133,146,449,-195,-483,-161,246,31,-361,109,66,-945,83}

    {-18,91,-355,-453,-72,120,333,-1,993,-889,246,80,61,-32,-107,116,-447,476,607,109,-75,109,-884,321,105,-839,-19,-50,572,-87,521,112,227,-122,220,-49,432,-101,127,-18,118,582,619,-140,-87,-220,200,-124,-745,155}

    {1,3,7,14,17,22,29,34,37,37,46,50,56,56,60,64,67,73,75,80,87,93,97,100,102,108,116,123,126,127,135,141,147,149,152,153,161,163,171,174,179,188,197,198,207,210,215,217,226,235}

    9

    Returns: -1

  30. {827,841,387,127,-21,-329,722,106,-331,-519,-26,263,932,150,99,101,-122,248,136,-704,-908,-150,195,-62,-640,669,229,-231,819,30,-123,202,233,821,-672,169,57,607,429,164,645,-653,-33,-149,194,9,18,959,-114,-97}

    {812,878,252,987,-373,613,655,223,939,30,3,-628,-769,58,185,-883,49,64,206,-977,-485,-31,-61,94,-499,-242,62,-708,-727,242,440,-915,17,-751,629,-46,149,-160,-679,145,871,94,-46,218,33,-408,212,218,102,168}

    {1,9,18,27,35,41,44,52,57,60,69,75,84,90,97,106,108,115,117,125,133,134,140,145,147,147,154,155,159,163,164,164,168,168,177,179,187,189,189,193,198,200,202,207,215,224,230,233,240,249}

    6

    Returns: -1

  31. {-71,59,-122,-146,88,-374,-419,31,512,126,121,-746,-13,-650,879,-137,-21,114,-626,-58,14,-823,22,146,-976,-661,-893,33,12,208,-30,-80,724,-107,511,-202,-103,-138,107,131,558,51,23,681,-51,791,-900,-55,231,-968}

    {444,67,-92,204,35,791,-817,77,317,204,107,844,-126,-630,363,126,22,173,217,108,54,-669,152,-101,569,-289,983,-13,151,69,259,-141,910,197,-942,576,86,4,44,-97,233,-100,63,-152,69,337,531,93,-139,-695}

    {1,7,7,11,13,22,28,37,45,53,56,64,73,75,84,88,89,98,98,102,107,111,114,114,123,126,128,134,140,149,157,165,173,173,176,178,178,179,182,190,191,197,205,207,215,215,221,222,231,239}

    9

    Returns: -1

  32. {920,57,-10,159,721,1,-13,596,-289,977,-121,699,-523,-314,-890,795,169,-517,14,750,-328,52,-241,172,225,712,-338,-4,82,323,-300,-442,20,247,-29,-31,147,66,217,380,-400,774,-365,-65,-984,-10,110,240,22,443}

    {741,142,-379,44,-366,-43,202,296,851,-594,108,-450,-478,-267,797,44,69,-535,-891,998,402,157,328,-11,243,345,-219,330,335,567,-671,75,-135,-50,-7,152,-57,-544,193,-903,-581,572,-796,21,862,47,-78,41,158,209}

    {1,3,12,13,20,21,21,25,34,36,36,44,44,51,51,57,65,72,77,83,86,93,95,100,104,107,108,113,114,121,128,132,132,141,146,153,153,159,162,171,179,184,193,194,196,196,203,206,215,217}

    13

    Returns: -1

  33. {-37,165,-14,317,49,-568,173,-215,-26,-368,193,33,129,32,-408,-776,32,137,248,-392,111,71,-60,-57,155,217,152,-512,-828,114,636,-759,32,-71,558,705,-81,108,-954,-234,-54,239,873,-103,973,-979,80,127,42,-794}

    {134,-18,-30,59,148,785,-10,-305,45,-996,367,-12,-94,12,-891,-82,139,137,99,52,2,-133,13,51,-13,-737,-483,-220,886,559,-457,-884,-34,236,-268,-710,-67,200,-458,26,78,909,-510,134,654,-401,125,152,-101,235}

    {1,9,17,18,20,25,25,25,30,36,45,45,46,55,58,61,61,70,79,87,89,97,99,101,103,112,117,118,123,125,128,136,138,139,140,146,154,156,163,169,169,177,183,185,192,194,201,210,213,219}

    4

    Returns: -1

  34. {-150,454,-816,-35,-34,174,-247,58,18,58,21,147,-239,-966,-373,101,109,156,76,91,40,-69,205,130,184,284,553,-30,-842,917,168,-25,370,352,-98,114,666,33,217,98,-470,863,-5,-66,454,145,-47,69,589,11}

    {-91,-205,-902,-64,241,98,105,233,218,173,212,-74,-22,-679,-473,211,435,18,66,-21,-135,203,190,-572,-114,-674,-262,-106,-555,-674,-519,234,122,-421,-627,47,-883,189,103,-71,856,33,5,-96,355,238,829,-98,-537,153}

    {1,9,11,15,23,23,23,24,33,40,41,50,53,56,63,66,72,73,74,78,81,86,86,87,87,87,88,90,99,108,115,121,128,129,131,139,141,145,154,157,159,162,164,171,177,179,180,183,186,190}

    9

    Returns: -1

  35. {417,-2,-193,-491,911,-118,154,-105,315,646,142,-827,-22,-129,-807,19,672,-115,-667,-541,674,14,46,-104,-76,994,-828,-448,-25,-131,-24,201,591,28,-118,58,-27,883,112,58,528,216,177,-30,-91,83,212,110,-734,-50}

    {-796,116,-515,-104,-957,-67,-111,210,-529,-865,-99,-653,-107,141,30,-2,-187,-146,-478,925,848,-131,209,62,-11,-400,190,-584,201,237,124,50,-491,133,95,-448,-527,892,-675,34,584,244,51,199,208,246,-54,127,-448,-26}

    {1,1,9,18,18,23,26,30,34,38,40,47,50,51,55,55,58,64,66,74,78,86,95,101,110,117,121,121,130,135,137,143,150,152,158,166,173,182,184,188,191,197,200,206,215,222,230,234,240,241}

    5

    Returns: -1

  36. {4,-114,-27,168,619,251,-113,-123,-103,178,138,-1000,169,-800,129,878,31,38,13,136,64,71,719,-2,955,56,968,141,151,368,130,-16,-747,986,822,83,131,-735,-23,4,443,-75,152,-58,69,-17,-701,-914,159,111}

    {8,-891,11,72,-347,408,841,-823,881,-57,-26,41,9,355,42,-694,141,-66,-57,60,-51,-42,129,-69,994,369,-865,69,-42,881,122,36,990,77,747,128,31,587,-45,69,-913,478,-61,70,58,164,-122,-269,109,71}

    {1,2,5,11,18,25,25,31,31,32,35,42,47,56,62,65,65,72,78,83,84,88,96,104,105,109,117,118,122,129,138,145,145,147,152,159,168,173,177,178,184,193,193,197,198,206,213,214,220,226}

    16

    Returns: -1

  37. {-161,-15,115,48,134,482,-460,-163,129,109,162,-6,-19,-947,-168,411,-145,619,110,648,-151,-155,500,-10,-289,-944,-786,102,322,674,-30,-840,14,27,23,90,-54,-5,52,-113,-67,917,-46,116,970,34,-33,-619,-227,-476}

    {586,169,109,126,101,638,-302,18,-64,-61,51,89,155,-376,-208,678,-33,-433,-55,-412,11,-510,-496,59,163,-970,-512,247,969,-182,115,554,-12,54,63,159,148,-55,123,-813,67,-933,-55,-793,-752,74,2,215,-957,-286}

    {1,6,13,18,23,26,33,39,42,50,50,54,60,64,69,74,83,85,91,91,93,93,102,106,109,109,113,114,116,119,123,130,130,133,135,143,150,151,155,155,164,170,174,182,182,183,186,188,192,194}

    11

    Returns: -1

  38. {596,-32,130,-61,108,137,-410,27,436,535,211,39,526,103,135,-46,191,156,156,889,-59,15,-757,-899,106,-66,910,166,-41,0,80,63,-561,-611,-139,23,119,9,120,-490,22,110,133,42,-390,253,-623,36,-46,165}

    {247,78,9,51,70,58,859,-49,-878,-854,-465,-52,145,-17,-70,-23,-198,-9,0,619,85,92,647,570,77,-66,-620,85,40,-367,-49,-19,-841,-233,-420,16,31,-562,151,853,113,161,157,146,-612,315,-151,-9,91,136}

    {1,10,16,22,31,40,43,49,57,58,62,71,78,85,88,92,94,97,97,103,110,110,118,119,127,129,132,134,142,142,146,152,161,161,166,166,167,175,184,193,194,199,208,217,221,225,230,236,243,251}

    7

    Returns: -1

  39. {267,-393,-154,115,877,-44,-946,-70,34,-101,153,-17,151,-933,163,925,1,161,-797,-535,116,32,-60,82,130,12,-373,88,5,-181,84,18,7,157,88,-18,729,103,84,-14,-998,398,-28,165,23,945,356,44,6,116}

    {292,-914,740,491,-829,-10,-710,61,148,400,5,-67,95,-842,160,-618,6,542,42,216,161,48,-50,75,156,-7,497,33,107,-842,32,143,65,133,-51,110,120,-794,-671,526,164,505,45,-49,220,583,-564,49,148,35}

    {1,10,10,15,23,30,31,34,35,43,44,51,56,56,57,59,59,60,61,68,77,85,86,95,104,106,111,116,117,125,125,126,134,136,144,152,161,170,172,173,173,178,178,185,190,193,193,199,203,206}

    14

    Returns: -1

  40. {736,24,-730,133,-241,-471,17,-6,677,137,35,347,-48,-61,-27,-466,-400,119,127,534,130,162,963,-763,380,383,716,93,-47,42,480,53,86,83,15,-2,-25,-705,484,-66,54,-481,974,-935,86,166,-400,534,-87,-501}

    {-376,-958,-812,91,837,125,163,140,-435,58,-491,602,53,167,55,-763,-212,100,56,830,-515,-61,-652,-985,-103,-162,-776,-49,107,109,111,52,48,-43,-28,27,169,-335,238,63,78,747,705,671,59,159,908,-861,587,997}

    {1,5,8,13,15,20,22,30,35,40,48,54,54,63,66,74,77,82,87,93,99,99,106,108,109,111,115,118,124,133,141,147,151,152,155,163,171,178,184,187,190,197,198,201,207,214,218,227,229,238}

    5

    Returns: -1

  41. {40,-16,584,-131,56,551,146,-686,-295,-56,361,271,553,156,3,-927,-57,151,-105,961,-272,133,63,-47,156,117,-17,-238,-226,948,-25,-16,103,44,679,-12,46,-36,-29,308,-22,26,-421,141,-392,582,-543,25,-29,-91}

    {48,91,-885,-105,123,-171,112,-864,148,56,641,60,-355,114,-2,-677,-69,41,640,-834,-92,-4,-59,44,-588,23,-818,-131,542,-902,161,-19,114,164,-252,-62,837,46,71,-15,44,81,-956,-17,-288,-401,-159,139,-6,-963}

    {1,2,6,11,20,21,24,26,28,33,42,48,56,62,70,73,74,75,75,81,90,98,103,110,114,122,125,125,131,139,141,144,153,161,169,169,178,182,184,186,195,196,196,205,214,214,218,219,220,224}

    5

    Returns: -1

  42. {431,79,241,267,85,-43,473,677,48,575,109,879,1,127,-514,-986,58,145,-40,-769,520,617,-43,481,24,266,-23,-15,-573,193,25,93,-9,-61,124,146,-601,-846,-50,85,286,962,55,56,-42,54,-944,86,296,16}

    {41,21,-811,-913,-33,108,353,-775,-63,781,168,-530,44,101,218,-680,77,-49,-969,216,957,317,169,731,9,114,99,415,924,288,-42,-47,33,43,-51,-58,-846,962,140,101,299,158,76,41,-61,-68,-629,-42,536,-598}

    {1,10,13,14,17,20,24,27,33,37,41,49,54,56,58,60,69,70,75,77,81,86,95,95,95,103,105,105,105,109,114,119,122,123,130,138,144,147,148,152,159,167,170,172,172,179,183,184,192,194}

    13

    Returns: -1

  43. {42,-17,606,168,491,82,-92,-932,84,51,-21,-953,-736,-31,-855,779,-89,115,-46,-66,-191,-812,-899,185,40,-7,133,-194,-166,16,-180,-97,-58,-27,-930,97,-246,-464,78,151,-6,71,92,803,-121,152,138,791,-21,118}

    {-59,-64,-911,497,26,76,-511,-265,103,113,422,-758,784,70,-775,855,61,-464,115,17,146,486,-579,804,-63,-143,157,983,-353,78,884,-958,84,-45,540,-62,-854,-972,107,146,79,-6,27,136,50,63,-453,669,54,112}

    {1,8,10,11,11,15,15,23,27,30,33,38,39,42,45,49,50,52,52,59,59,65,71,72,72,76,78,80,85,89,89,93,94,98,105,106,115,122,131,136,136,140,142,145,145,153,153,154,154,156}

    3

    Returns: 142

  44. {-97,67,985,44,136,529,162,160,-45,38,126,6,43,169,917,198,-190,142,-622,-15,653,531,727,-454,857,914,50,-47,-955,174,-9,98,-65,-46,39,736,-36,76,2,29,246,-42,61,41,478,-466,621,845,709,556}

    {-807,42,86,100,-38,-501,4,82,924,79,-50,-58,6,-45,-668,-906,-989,0,47,-17,-706,-708,171,356,158,-352,-4,122,-507,155,-21,-39,170,-13,720,537,42,-51,-14,-7,660,120,91,47,384,-20,-634,396,-405,413}

    {1,10,12,21,26,31,34,35,42,50,53,60,61,64,71,72,77,83,87,90,91,91,94,102,110,111,117,120,121,128,132,141,149,158,158,163,167,170,176,179,182,182,183,189,194,202,211,211,217,220}

    6

    Returns: 189

  45. {44,20,236,137,199,-837,129,69,156,44,842,80,867,649,-376,34,-18,-451,-86,-449,-478,5,525,164,94,27,-855,7,-338,723,35,131,22,0,118,3,-53,-481,-648,-214,475,-807,-45,-102,400,160,-51,147,-54,-414}

    {50,-34,-515,-19,423,-953,79,-53,-12,-55,-595,-35,757,632,641,-15,99,777,465,523,-438,121,274,569,36,137,199,55,290,-508,53,-986,-20,-2,142,108,-21,-329,-143,-772,297,262,-55,53,-550,51,-12,40,47,20}

    {1,2,4,11,14,16,25,25,27,31,35,41,42,48,50,55,59,63,69,75,82,84,85,93,95,104,104,104,111,113,115,118,124,130,131,132,141,141,143,146,153,161,162,162,166,170,176,176,176,180}

    7

    Returns: -1

  46. {-320,-54,-356,459,-35,166,-685,-978,16,-900,-404,92,68,5,45,321,141,-34,78,564,25,45,87,-502,22,41,94,128,60,76,-24,41,-493,-403,-53,0,164,-373,686,866,-716,839,191,-70,-51,30,3,360,-210,23}

    {-520,34,753,-975,138,-10,544,-136,60,-397,155,-22,91,4,89,-788,75,-46,124,-432,18,-14,-54,65,100,-35,-797,45,67,-15,138,87,-292,-486,151,41,151,-945,341,587,-785,-504,833,167,161,-9,-23,40,-760,-70}

    {1,1,9,18,25,26,34,36,43,50,56,62,69,69,71,71,72,72,77,80,82,86,90,91,93,102,107,113,115,120,126,134,139,143,152,156,164,164,172,179,186,190,193,197,203,208,214,221,228,229}

    8

    Returns: 134

  47. {-65,-838,490,3,161,923,77,37,-11,-19,97,-23,-14,-31,240,315,-1,278,-23,-287,473,534,-6,-75,151,164,-28,184,134,17,920,776,155,-34,460,145,-555,-9,-690,-28,155,172,112,-11,-23,116,58,-675,-55,848}

    {58,-652,-62,-6,152,100,101,66,127,64,153,760,470,137,-718,-513,-16,-716,122,525,-448,561,-54,354,38,107,-15,669,-33,113,74,-984,110,-989,308,91,-331,-38,-852,67,96,-515,92,72,48,-6,-38,-719,8,592}

    {1,7,11,11,20,24,28,31,32,32,36,37,42,51,58,60,60,68,68,74,75,75,80,81,83,91,100,105,114,119,119,119,122,128,131,133,133,140,148,149,156,158,163,165,168,172,179,183,186,193}

    7

    Returns: -1

  48. {73,2,-26,58,-29,693,-11,-448,36,147,70,-347,-221,-573,42,-965,49,136,324,-31,-23,66,-19,855,111,-859,327,-233,170,14,115,33,152,-715,33,-554,-50,-700,-2,655,68,9,134,-16,21,-721,802,12,84,126}

    {51,131,40,-25,99,473,-66,-858,138,135,118,-770,631,-487,169,604,102,-52,905,42,74,145,-7,127,-42,837,406,-984,-222,138,92,160,127,287,77,943,124,-419,642,-444,158,62,-12,-31,37,-583,-533,-31,4,929}

    {1,8,8,9,11,14,21,25,25,28,34,36,38,39,48,52,61,67,71,75,77,82,89,96,105,112,121,128,132,140,148,152,157,157,165,165,168,175,181,186,188,190,199,205,208,209,209,211,220,224}

    14

    Returns: -1

  49. {-25,27,33,-131,105,-868,10,-450,-31,-57,773,-974,84,-284,905,-907,21,-54,-102,8,529,97,99,100,44,-44,953,90,-838,140,-28,57,143,118,-64,198,148,91,748,739,104,34,765,-189,-11,226,98,-48,730,40}

    {31,-185,-567,738,-5,34,98,243,-79,52,-877,-32,52,-528,606,-315,110,-626,940,70,-888,-14,-67,120,-61,105,-783,-14,-687,-2,96,-12,6,4,-207,610,-11,43,-591,-66,165,10,460,-371,-70,65,121,110,439,115}

    {1,1,6,11,16,19,22,24,29,33,41,44,49,57,65,68,77,84,85,90,98,98,104,111,116,117,120,127,127,131,132,137,142,148,148,150,151,156,162,169,178,182,184,190,192,194,196,200,201,204}

    12

    Returns: -1

  50. {98,6,-78,193,136,140,-39,46,545,48,45,50,47,79,57,11,-353,42,853,-614,-411,59,813,2,-217,535,-5,-46,-74,-881,-984,-30,-47,156,172,156,-861,36,871,241,-412,138,-68,194,-490,-68,-17,-286,34,90}

    {-34,27,121,-530,-29,145,146,36,-36,18,710,156,-70,-1,13,5,527,171,650,397,969,-763,-688,-36,432,-621,-34,-8,-349,-272,703,50,-792,100,-779,-47,841,-6,998,-639,-729,-19,42,-261,927,125,158,453,147,-30}

    {1,1,6,7,10,12,15,18,19,22,22,22,30,35,43,44,49,50,53,56,65,67,69,71,78,86,86,86,90,93,93,95,100,108,113,121,123,132,133,136,140,144,147,149,158,161,166,170,177,186}

    3

    Returns: 22

  51. {7,-62,945,-226,-411,0,999,-874,91,6,-161,-39,-49,93,70,-60,225,-905,0,-451,939,-486,124,-627,12,-632,-914,887,-46,752,163,-217,-753,-49,18,-607,570,102,-924,-783,-457,-84,-37,72,650,-961,-774,-126,-27,124}

    {60,631,298,-823,561,4,-898,647,-979,120,-44,98,93,143,119,-60,596,-262,-31,230,-488,512,124,-435,6,352,-838,-468,-65,854,-16,-237,41,89,22,-399,-696,-53,806,-674,3,-239,138,60,521,561,-512,-327,-16,126}

    {1,7,14,22,26,35,39,47,54,58,58,67,76,85,94,98,100,107,115,122,131,133,137,141,147,156,163,171,172,181,186,189,196,198,199,201,204,211,213,213,214,216,218,221,224,227,236,243,243,250}

    13

    Returns: -1

  52. {942,145,-213,716,-628,742,494,101,85,28,-930,-553,-322,-906,-791,-48,30,112,-845,42,-28,-660,230,135,82,150,-220,145,499,-38,157,440,49,-576,-38,94,-835,-65,24,70,33,-50,154,92,119,-682,-690,-22,137,-977}

    {446,-62,921,-325,161,803,521,10,22,152,618,-852,-542,339,-428,64,70,38,375,164,-63,-765,681,33,-34,117,-173,23,-168,152,60,-723,32,141,57,-10,-57,121,70,122,103,55,73,-36,31,733,793,-70,-66,-276}

    {1,10,18,24,30,36,42,46,54,60,67,73,80,86,94,96,104,108,117,126,135,138,145,149,156,161,162,167,172,176,177,184,187,196,202,202,210,212,216,224,224,227,232,241,250,253,254,263,270,270}

    13

    Returns: -1

  53. {-635,813,6,-44,-27,-656,-631,133,20,-446,-246,8,-20,-137,-372,75,842,-153,-934,191,563,16,30,127,-828,-110,-62,79,19,-559,-65,70,811,-489,881,-506,154,36,627,-361,81,938,647,664,-642,78,459,-801,-37,525}

    {-53,798,74,124,89,654,873,-830,-19,113,-389,-580,87,980,-69,126,-527,786,521,658,-576,15,-17,53,-341,510,74,-62,18,252,-4,111,-393,-762,639,735,42,120,905,-200,138,-927,220,-543,-948,15,-829,-918,120,250}

    {1,3,12,13,19,19,25,29,35,41,43,51,52,53,59,59,64,72,78,82,84,88,97,98,99,108,110,111,111,115,122,129,135,141,149,153,161,167,168,175,179,184,191,196,202,205,212,216,217,220}

    2

    Returns: 88

  54. {-28,144,82,-357,163,165,48,608,89,234,148,-348,-155,135,-673,74,187,-32,73,677,129,91,631,15,-103,-67,117,14,70,2,-543,238,-670,62,38,128,170,-899,161,-302,164,10,350,91,-477,79,389,268,854,-982}

    {20,-53,59,-869,99,12,-40,322,96,-939,36,-652,-144,-46,639,21,935,80,953,-851,-18,113,386,19,-861,11,40,82,25,-29,103,235,-162,163,14,77,4,223,-17,-571,-26,-38,-666,70,812,99,992,303,128,944}

    {1,10,12,19,21,29,36,45,45,52,57,60,62,67,71,71,76,83,88,92,96,103,109,111,120,129,136,136,137,140,148,153,157,159,163,170,170,171,179,181,181,185,190,195,196,196,201,208,217,217}

    6

    Returns: 137

  55. {-139,3,146,162,-913,295,-42,705,-549,5,31,185,116,-973,90,-24,41,628,-60,-743,-522,56,32,-65,5,478,762,438,-639,18,465,222,669,107,36,-56,-373,-64,134,-364,-2,-571,821,-974,-544,203,-12,-923,-170,111}

    {892,70,109,47,253,-727,106,-429,712,166,103,176,40,551,68,18,150,-750,137,882,-114,-38,50,75,-26,-676,467,579,960,-24,260,408,162,137,163,6,-169,98,91,-458,346,-575,276,-978,976,342,35,-160,592,114}

    {1,6,12,18,26,28,29,33,41,41,44,48,55,56,65,65,67,72,78,87,94,94,103,111,118,119,127,127,130,131,133,133,141,149,157,164,164,165,168,168,169,175,180,181,190,196,197,200,203,210}

    8

    Returns: -1

  56. {50}

    {50}

    {5}

    1

    Returns: 5

  57. {-1}

    {100}

    {5}

    1

    Returns: -1

    The only apple falls outside your garden.

  58. {0,75,0,35,12,85,0,0,0,0,0,0,0,16,0,73,0,52,0,0,0,56,30,0,35,63,44,0,0,44,28,0,18,24,0,0,9,0,0,75,0,0,6,0,0,0,47,0,91,0}

    {0,84,0,80,42,37,0,0,0,0,0,0,0,81,0,19,0,92,0,0,0,67,75,0,41,62,78,0,0,69,100,0,52,35,0,0,38,0,0,35,0,0,94,0,0,0,66,0,0,0}

    {1,10,19,28,33,38,41,48,53,62,69,69,72,74,76,85,86,94,97,97,102,107,113,116,125,132,132,137,144,151,158,159,167,173,173,178,182,188,191,200,205,205,206,214,216,219,219,224,227,230}

    3

    Returns: 19

  59. {0,0,94,69,0,47,0,14,0,0,0,77,0,0,0,0,0,1,41,0,35,0,0,62,51,0,80,0,4,91,0,40,84,0,0,74,12,54,0,0,84,0,18,31,74,19,0,54,20,57}

    {0,0,99,43,0,15,0,63,0,0,0,22,0,0,0,0,0,66,26,0,7,0,0,92,40,0,10,0,41,98,0,25,52,0,0,35,25,21,0,0,46,0,29,43,52,83,0,60,48,7}

    {1,6,6,8,13,17,25,25,33,36,41,50,58,64,65,70,75,77,80,89,91,92,92,93,99,103,107,116,118,125,128,133,135,138,145,145,145,150,150,158,167,172,181,190,194,196,200,209,214,222}

    10

    Returns: 36

  60. {43,19,0,0,21,0,38,4,0,0,0,0,0,39,0,0,44,23,0,0,0,17,20,0,44,14,89,0,47,0,0,57,86,0,34,0,45,0,78,1,52,58,87,19,0,0,82,7,16,86}

    {84,81,0,0,26,0,84,81,0,0,0,0,0,32,0,0,5,23,0,0,0,78,73,0,63,36,37,0,44,0,0,94,0,0,63,0,76,0,73,61,10,19,31,30,0,0,17,22,33,43}

    {1,5,9,11,13,13,21,24,33,40,49,50,51,56,57,60,62,67,68,74,79,85,93,97,105,107,115,120,128,135,143,149,152,156,164,169,174,182,191,195,203,211,218,227,233,241,243,251,256,261}

    5

    Returns: 13

  61. {0,0,0,0,0,0,84,0,39,0,0,80,0,35,0,0,19,50,18,63,0,0,0,0,0,4,0,23,0,0,0,0,0,74,0,0,0,0,0,22,0,79,0,0,0,10,0,100,0,37}

    {0,0,0,0,0,0,19,0,75,0,0,41,0,87,0,22,65,64,63,48,0,0,0,0,0,74,0,47,0,0,84,0,0,7,0,0,0,0,0,33,0,63,0,0,0,20,0,81,0,77}

    {1,10,19,24,32,32,41,47,47,54,56,56,59,61,68,69,75,78,85,92,92,93,95,95,100,108,108,111,111,112,116,117,118,123,129,138,146,153,161,169,174,174,175,183,187,195,196,196,197,206}

    8

    Returns: 47

  62. {0,0,53,0,0,0,32,0,51,85,29,0,63,0,0,48,83,0,73,0,0,0,0,0,0,0,0,21,56,0,82,29,81,0,94,72,0,25,0,0,0,84,0,39,56,0,0,38,0,0}

    {0,0,45,0,0,0,43,0,78,99,93,0,28,0,0,21,45,0,13,0,0,0,0,0,0,0,0,46,8,0,71,56,96,0,20,7,0,63,0,0,0,42,0,90,15,0,0,26,0,0}

    {1,5,10,18,22,24,32,35,37,39,40,45,46,48,49,53,56,61,67,70,74,81,82,84,90,91,99,102,106,115,115,118,121,128,131,138,147,148,151,154,157,163,163,170,178,179,180,184,193,202}

    12

    Returns: 45

  63. {52,0,15,26,12,0,0,34,78,0,0,0,76,12,0,0,62,91,20,0,37,0,52,34,14,16,6,0,0,0,0,39,0,26,31,50,99,27,84,0,0,56,83,75,34,27,0,0,0,65}

    {35,0,13,87,20,0,0,93,57,0,0,0,95,19,0,0,70,57,53,0,66,0,75,48,59,75,75,0,0,0,0,72,0,48,24,31,41,93,24,0,0,38,64,42,58,23,0,0,0,54}

    {1,2,2,9,15,22,28,30,35,37,44,51,51,51,54,59,63,64,70,71,76,76,85,85,85,90,91,98,100,101,105,114,116,123,132,132,138,143,148,150,159,161,162,162,167,173,180,189,196,200}

    4

    Returns: 9

  64. {0,0,48,0,20,0,71,0,75,0,83,12,61,0,0,69,64,92,84,21,28,0,63,0,0,0,0,0,0,45,28,41,69,0,27,56,0,98,0,89,19,0,0,0,81,0,15,0,70,99}

    {0,0,55,0,74,0,83,0,30,0,0,59,84,0,0,10,24,15,74,92,70,0,7,0,0,0,0,0,0,84,86,28,47,0,88,87,0,70,42,76,12,0,0,0,77,0,73,0,49,47}

    {1,3,5,6,11,16,19,24,24,28,37,37,44,51,52,58,63,71,76,76,79,82,84,91,99,99,108,114,114,115,122,130,133,134,143,151,158,162,167,176,176,180,180,187,188,191,196,203,206,208}

    7

    Returns: 19

  65. {18,27,99,2,0,27,0,0,0,25,0,0,0,4,0,39,5,0,55,16,0,87,0,0,0,45,36,0,73,0,0,0,95,0,0,60,44,0,3,65,22,68,4,100,0,0,38,9,0,0}

    {25,11,45,21,0,92,0,0,0,71,0,0,0,73,0,89,32,0,52,2,0,40,0,0,0,74,58,0,49,0,0,0,41,0,0,50,39,0,95,99,30,73,42,59,0,0,13,44,0,0}

    {1,10,14,14,23,26,33,39,48,57,64,67,67,68,74,80,84,90,90,94,95,100,102,105,107,114,115,119,120,124,131,135,139,140,145,150,157,159,163,169,170,171,172,175,179,187,189,189,193,195}

    14

    Returns: 68

  66. {79,0,0,19,0,32,87,2,0,56,0,0,0,87,61,48,70,76,0,39,0,34,0,0,97,0,0,67,0,0,90,94,19,7,0,8,5,0,0,58,21,0,89,59,22,0,7,58,0,12}

    {98,0,0,89,0,76,46,39,0,96,0,0,0,87,71,68,95,77,0,72,0,21,0,0,46,0,0,19,0,0,32,17,74,45,0,13,20,0,0,28,80,0,92,34,39,0,2,34,0,1}

    {1,3,12,18,25,30,32,36,45,49,52,54,59,62,63,66,71,80,86,86,94,99,107,110,114,114,120,124,127,128,132,138,141,145,149,149,150,156,163,165,168,168,172,172,175,183,187,187,194,196}

    10

    Returns: 49

  67. {0,0,62,0,58,60,0,0,0,46,0,26,36,96,69,0,67,0,0,0,0,0,88,0,0,62,0,44,9,10,21,25,37,0,0,0,8,0,83,92,28,68,0,0,0,52,0,0,0,0}

    {0,0,51,0,81,84,0,0,0,67,0,14,59,60,63,0,21,0,0,0,0,0,38,0,0,68,0,52,30,14,76,73,62,0,0,0,42,0,56,35,94,79,0,0,0,79,0,0,0,0}

    {1,5,7,9,15,15,24,29,33,37,42,48,48,53,53,55,57,66,70,76,77,78,82,85,86,95,101,105,111,117,122,126,129,136,144,153,162,169,174,177,181,181,183,187,193,195,204,204,205,210}

    7

    Returns: 24

  68. {150 }

    {150 }

    {1 }

    1

    Returns: -1

  69. {1, 101 }

    {1, 101 }

    {1, 2 }

    1

    Returns: 1

  70. {14, -958, 38, 32, 69 }

    {48, 485, 58, 76, 75 }

    {1, 2, 3, 6, 15 }

    3

    Returns: 6

  71. {0, 0 }

    {0, 0 }

    {1, 1 }

    1

    Returns: 1

  72. {50, 150 }

    {50, 150 }

    {1, 100 }

    2

    Returns: -1

  73. {-1 }

    {-1 }

    {1 }

    1

    Returns: -1

  74. {0 }

    {0 }

    {123 }

    1

    Returns: 123

  75. {50, -1 }

    {50, -1 }

    {1, 1 }

    2

    Returns: -1

  76. {5 }

    {5 }

    {365 }

    1

    Returns: 365

  77. {100, 100, 100, 100 }

    {100, 100, 0, 0 }

    {1, 2, 3, 4 }

    2

    Returns: 2

  78. {0, -1 }

    {0, -1 }

    {5, 7 }

    2

    Returns: -1

  79. {1, 1 }

    {1, 1 }

    {1, 1 }

    1

    Returns: 1

  80. {100, 100, 100, 100, 100, 100 }

    {100, 10, 100, 100, 100, 100 }

    {1, 2, 10, 15, 20, 25 }

    5

    Returns: 20


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: