It seems that this problem [hyperlinked] has weak test cases, or has forgotten to add a statement in the problem, that a[i] and b[i] are from 1 to n. The following is the test case which gives the wrong answer for a lot of programs:
Click to view
1
100 2
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000
99900 99901 99902 99903 99904 99905 99906 99907 99908 99909 99910 99911 99912 99913 99914 99915 99916 99917 99918 99919 99920 99921 99922 99923 99924 99925 99926 99927 99928 99929 99930 99931 99932 99933 99934 99935 99936 99937 99938 99939 99940 99941 99942 99943 99944 99945 99946 99947 99948 99949 99950 99951 99952 99953 99954 99955 99956 99957 99958 99959 99960 99961 99962 99963 99964 99965 99966 99967 99968 99969 99970 99971 99972 99973 99974 99975 99976 99977 99978 99979 99980 99981 99982 99983 99984 99985 99986 99987 99988 99989 99990 99991 99992 99993 99994 99995 99996 99997 99998 99999
Output
0 1
Solutions:
Click to view
Solution: 19348427 | CodeChef
Solution: 19298760 | CodeChef
Solution: 19298630 | CodeChef
Solution: 19346597 | CodeChef
Solution: 19348427 | CodeChef
Runtime error:
Click to view
Correct answer (I believe)
100 269379823
My solution for the same: here
Please note this, and either add in the problem statement that a[i] is from 1 to n, or increase the number of test cases. Thank you!