Problem Statement
A[0] = a0 A[1] = a1 for i = 2 to n-1: A[i] = (A[i-1] * a2 + A[i-2] * a3 + a4) mod a5The array B is generated from the
Definition
- Class:
- SumOfArrays
- Method:
- findbestpair
- Parameters:
- int, int[], int[]
- Returns:
- String
- Method signature:
- String findbestpair(int n, int[] Aseed, int[] Bseed)
- (be sure your method is public)
Constraints
- n will be between 3 and 100,000, inlusive.
- Aseed and Bseed will contain exactly 6 elements.
- Aseed[5] and Bseed[5] will be between 2 and 100,000, inclusive.
- Aseed[0], Aseed[1], Aseed[2], Aseed[3], Aseed[4], will be between 0 and Aseed[5]-1, inclusive.
- Bseed[0], Bseed[1], Bseed[2], Bseed[3], Bseed[4], will be between 0 and Bseed[5]-1, inclusive.
Examples
3
{1,1,1,1,1,2}
{1,1,1,1,1,2}
Returns: "3 2"
Arrays are {1,1,1} and {1,1,1}, any permutation gives array {2,2,2} so answer is 3 occurrences of 2.
3
{1,1,1,1,1,4}
{1,1,1,1,1,4}
Returns: "2 4"
Arrays are {1,1,3} and {1,1,3}. If two arrays stay unchanged array of sums will be {2,2,6}, it have two occurrences of 2. But if we permute elements in first array and get array {1,3,1} then array of sums will be {2,4,4}, it have also two occurrences, but in this case second value is 4 which is better.
3
{1,2,0,0,1,5}
{1,2,0,0,1,5}
Returns: "2 3"
3
{1,2,0,0,1,5}
{0,1,0,0,1,5}
Returns: "3 2"
Arrays are {1,2,1} and {0,1,1}. Its possible to permute elements to get array {2,2,2}, so answer is pair 3 2.
14
{5,6,2,4,6,11}
{6,5,2,4,2,7}
Returns: "9 7"
100000
{1,2,3,4,5,6}
{1,2,3,4,5,6}
Returns: "100000 5"
100000
{1,2,3,4,5,100000}
{1,2,4,3,2,100000}
Returns: "12418 99987"
100000
{6274,99908,61138,86540,56297,100000}
{28275,25494,65423,61118,64925,100000}
Returns: "3027 102148"
100000
{1,2,1,0,2,100000}
{1,2,1,0,2,100000}
Returns: "99998 100000"
100000
{99999,99999,0,0,99999,100000}
{99999,99999,0,0,99999,100000}
Returns: "100000 199998"
100000
{0,3,1,0,3,99999}
{12,15,1,0,3,99999}
Returns: "99999 99996"
100000
{0,3,1,0,3,99999}
{0,4,1,0,4,100000}
Returns: "25003 99996"
100000
{0,4,1,0,4,100000}
{0,4,1,0,4,100000}
Returns: "100000 99996"
100000
{0,4,1,0,4,100000}
{0,5,1,0,5,100000}
Returns: "20000 100011"
100000
{0,5,1,0,5,100000}
{0,6,1,0,6,99996}
Returns: "16670 99995"
100000
{0,6,1,0,6,99996}
{0,8,1,0,8,100000}
Returns: "25003 99998"
100000
{0,9,1,0,9,99999}
{0,2,1,0,2,100000}
Returns: "11112 99998"
100000
{0,9,1,0,9,99999}
{0,10,1,0,10,100000}
Returns: "10009 99990"
99999
{11,22,1,0,11,99990}
{0,12,1,0,12,99996}
Returns: "8339 100039"
100000
{0,12,1,0,12,99996}
{0,13,1,0,13,99996}
Returns: "7693 100019"
100000
{0,13,1,0,13,99996}
{0,13,1,0,13,99996}
Returns: "99996 99983"
100000
{0,14,1,0,14,99988}
{0,14,1,0,14,99988}
Returns: "99988 99974"
100000
{0,15,1,0,15,99990}
{0,15,1,0,15,99990}
Returns: "99990 99975"
100000
{0,16,1,0,16,100000}
{0,16,1,0,16,100000}
Returns: "100000 99984"
100000
{0,20,1,0,20,100000}
{0,20,1,0,20,100000}
Returns: "100000 99980"
99734
{1251,2734,252,14544,5252,98765}
{12416,6146,73432,1231,74234,89991}
Returns: "20489 91657"
100000
{1241,12512,23121,51241,32532,67777}
{21311,12414,12412,53122,12321,68888}
Returns: "8944 68977"
100000
{15724,19169,26500,6334,18467,99959}
{28145,5705,24464,26962,29358,98522}
Returns: "36132 98908"
99999
{26841,30145,18979,23135,19544,93007}
{29136,11787,3752,29833,25884,95238}
Returns: "347 93596"
100000
{20206,21023,19481,28953,16930,92958}
{29797,9568,9835,15362,14743,91320}
Returns: "19900 91461"
100000
{1791,13726,13328,13947,14839,92919}
{30325,7793,1594,16893,12384,99506}
Returns: "33094 99407"