Problem Statement
You are playing TopRPG, the latest and hottest new console-style RPG (role-playing game) to hit the market. Much like many RPGs, it features the main characters getting stronger as the game progresses by obtaining a nebulous sort of thing known as experience, which is typically acquired by killing monsters.
The strategy guide open in front of you tells you how much experience you'll need to get to each level, represented as a
You have 0 experience at the start, and you are about to go through an area where you will get a fixed amount of experience. You want to know how far you will be from the next level after you finish. Given a
Definition
- Class:
- LevelUp
- Method:
- toNextLevel
- Parameters:
- int[], int
- Returns:
- int
- Method signature:
- int toNextLevel(int[] expNeeded, int received)
- (be sure your method is public)
Constraints
- expNeeded will contain between 1 and 50 elements, inclusive.
- Each element in expNeeded will be greater than all elements with lower indices.
- All elements in expNeeded will be between 1 and 999999, inclusive.
- received will be between 0, inclusive, and the largest element of expNeeded, exclusive.
Examples
{150,450,900,1800}
133
Returns: 17
You receive 133 experience, which isn't enough to get to level 1. You need is 150 - 133 = 17 more to get there.
{150,450,900,1800}
312
Returns: 138
With the same situation, you now receive 312 experience. The first 150 advances you to level 1. There is 162 left, which then goes to the 450 - 150 = 300 experience you need to get from level 1 to level 2. Thus to get to the next level (2), you need 300 - 162 = 138 more experience.
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,999999}
157632
Returns: 842367
{150,450,900,1800}
612
Returns: 288
{159,212,599,920,1055,1359,1838,2241,2693,4195,5381,6818,7838,8888,10591,18782,19298,22195,28571,33318,35838,38691,44129,49831,54203,59005,65536,78371,88888,91203,97381,105883,157372,188281,195105,215832,245773,274831,293030,315838,375045,391885,412583,433818,583772,677731,683871,735885,870938,999999}}
375612
Returns: 16273
{150,450,900,1800}
450
Returns: 450
You advance exactly to level 2, and thus need 900 - 450 = 450 experience to get to the next level.
{5487, 10989, 17046, 23592, 30905, 36820, 42594, 46574, 50052, 53216, 57032, 57846, 63933, 71256, 73871, 83767, 85871, 88262, 97900, 101917, 103402, 106719, 112613, 119359, 119915, 123096, 132363, 134593, 134962, 135569, 138750, 140959, 147068, 152658, 157765, 167539, 169044, 169925, 173679, 175015, 175412, 179335, 181485, 184321, 185567, 190332, 193065, 202767, 206276, 214999}
79663
Returns: 4104
{2040, 8005, 16097, 25045, 34191, 41551, 49081, 54948, 62915, 63626, 71702, 72131, 74784, 77968, 78171, 82330, 82747, 83057, 84904, 85719, 89952, 93949, 97600, 99431, 104545, 107281, 115166, 120141, 127952, 129556, 135878, 145729, 153298, 154064, 162864, 165931, 170409, 176739, 185673, 188119, 191513, 198524, 207751, 213798, 220345, 226127, 232685}
142959
Returns: 2770
{8405, 12536, 19213, 21615, 25750, 30610, 34479, 41350, 44095, 52939, 57622, 58323, 63489, 64375, 72645, 78578, 88264, 95953, 102716, 105085, 111709, 120918, 126681, 136668, 141456, 149618, 156152, 163075, 167796, 171294, 180661, 183787, 191417, 197462, 202991, 204756, 212013, 221411, 226399, 226402, 234644, 240667, 241371}
64236
Returns: 139
{5327, 7373, 10321, 13337, 22146, 23815, 29807, 34178, 41610, 47589, 56748}
6583
Returns: 790
{6082, 6398, 12410, 17860, 21302, 31296, 39143, 44466, 46225, 51329, 52402, 55501, 56960, 62628}
21247
Returns: 55
{5429, 7814, 11657, 19132, 20817, 24028, 26664, 30019, 39223, 46230, 53369, 58552, 61071, 63805, 71502}
18883
Returns: 249
{61, 6816, 16013}
1149
Returns: 5667
{872, 9038, 15097}
1093
Returns: 7945
{7518, 15132, 18224, 24258, 33653, 39130, 45359, 48581, 55744, 65185, 71043, 77913, 86558, 95776, 99785, 99965, 101702, 108446}
69907
Returns: 1136
{2498, 6788, 16586, 24633, 25330, 26082, 35002, 40217, 47028, 54246, 63431, 64113, 65297, 67574, 70642, 71221, 78976, 88274, 88427, 89697, 98436, 104447, 112587, 116323, 117904, 120053, 123969, 133639, 138884, 147030, 149743, 153839, 162627, 165138, 167281, 173119, 176382, 177445, 178498, 184925, 189558, 189796, 193257}
37035
Returns: 3182
{203, 9814, 10403, 15262, 15528, 17884, 20676, 23709, 29885, 35646, 41264, 48257, 51704, 55234, 61215, 64105, 73140, 74718, 82340, 89069, 94201, 103213, 106045, 114309, 120006, 124510, 134261, 136933, 145844, 152485, 153401, 158867, 165119, 166624, 166950, 169821, 170035, 179505, 185409, 188151, 193383, 201257, 210992}
137319
Returns: 8525
{2068, 6341, 13133, 16779, 25027, 34900, 40030, 47290}
17817
Returns: 7210
{9309, 12871, 22369, 30702, 39527, 42018, 51267, 55558, 64301, 71407, 72376, 80342, 84014, 84454, 88325, 94739, 96763, 104860, 107362, 114417, 120271, 124841, 126170, 135168, 139737, 149314, 158186, 167885, 171074, 175355, 184801, 193651, 197846, 206790, 210325, 213345, 214780, 217564, 221228, 227759, 234001, 238634, 243131, 249398, 254471, 259191}
30612
Returns: 90
{2818, 4353, 4858, 9882, 12340, 20526, 24549, 27928, 32043, 41290, 44368, 48024, 51552, 60429, 62935, 70659, 74832, 80873, 87969, 93578, 98755, 99515, 108007, 115778, 121172, 130513, 134551, 141370, 141784, 144856, 145125, 154709, 155668, 156442, 161050, 164467, 169779, 178410, 185206, 194633, 202511, 208738, 211821, 219580, 224684, 226625, 228460, 237737}
179156
Returns: 6050
{1238, 7101, 13145, 19227, 22861, 24299, 29723, 33748, 38357, 40547, 47644, 52522, 54296, 58704, 60708, 67090, 74916, 82232, 87246, 88220, 91315, 100559, 104112, 106642, 113645, 118654, 119477, 124667, 125306, 126815, 130937, 132814}
4064
Returns: 3037
{4312, 11671, 19627, 25715, 33451, 36016, 44294, 45479, 52923, 52975, 58568, 64368, 67154, 76925, 80042, 87842, 88588}
18932
Returns: 695
{651, 5746, 12498, 18159, 20429, 22372, 28672, 32452, 34869, 39398, 40550, 49485, 58326, 63189, 70080, 71361, 73960, 79768, 89327, 93111, 96363, 102326, 111704, 117109, 125859, 135008, 143530, 146432, 152679, 160117, 166416, 173315, 182200, 185252, 194164, 195320, 196667, 201879, 206815, 210579, 220320, 222760, 225459, 230394, 237698, 243640, 246208, 256111}
63088
Returns: 101
{40, 1395, 5838, 11608, 18368, 21561, 22832, 24466, 26914, 34433, 43505, 48604, 49374, 57332, 61835, 71517, 80631, 86481, 87727, 91777, 97743, 105082, 111572, 120237, 122511, 122657, 127264, 132107, 138509}
8307
Returns: 3301
{6442, 10507, 18273, 26837, 27662, 34974, 44809, 47268, 53380, 60734, 62265, 63476, 67952, 73793, 79508, 83666, 88621, 90186, 95590, 100947, 108479, 111223, 119423, 121972}
3426
Returns: 3016
{3509, 6074, 7174, 13393, 15633, 23175, 23459, 23466, 25924, 33385, 37056, 39350, 49270, 59053, 65053, 72856, 73850, 74327, 77972, 84681, 89316, 94268, 98895, 105287, 105597, 107756, 113244, 118106, 122814, 129672, 132880, 137449, 143225, 147534, 148322, 156338, 164541, 171965, 176340, 177002, 181887, 189933, 199241, 204046, 208227, 213535, 222496}
173560
Returns: 2780
{ 1, 450, 900 }
450
Returns: 450
{ 100 }
0
Returns: 100
{ 150, 300, 450 }
300
Returns: 150
{ 150, 450, 900, 1800 }
0
Returns: 150
{ 150, 450, 900, 1800 }
1000
Returns: 800
{ 150, 450, 900, 1800 }
450
Returns: 450
{ 10, 20 }
12
Returns: 8