{"problem":{"name":"Impartial Gift","description":{"content":"Takahashi has decided to give **one** gift to Aoki and **one** gift to Snuke.   There are $N$ candidates of gifts for Aoki, and their values are $A_1, A_2, \\ldots,A_N$.   There are $M$ candidates of g","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc302_d"},"statements":[{"statement_type":"Markdown","content":"Takahashi has decided to give **one** gift to Aoki and **one** gift to Snuke.  \nThere are $N$ candidates of gifts for Aoki, and their values are $A_1, A_2, \\ldots,A_N$.  \nThere are $M$ candidates of gifts for Snuke, and their values are $B_1, B_2, \\ldots,B_M$.\nTakahashi wants to choose gifts so that the difference in values of the two gifts is at most $D$.\nDetermine if he can choose such a pair of gifts. If he can, print the maximum sum of values of the chosen gifts.\n\n## Constraints\n\n*   $1\\leq N,M\\leq 2\\times 10^5$\n*   $1\\leq A_i,B_i\\leq 10^{18}$\n*   $0\\leq D \\leq 10^{18}$\n*   All values in the input are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ $M$ $D$\n$A_1$ $A_2$ $\\ldots$ $A_N$\n$B_1$ $B_2$ $\\ldots$ $B_M$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc302_d","tags":[],"sample_group":[["2 3 2\n3 10\n2 5 15","8\n\nThe difference of values of the two gifts should be at most $2$.  \nIf he gives a gift with value $3$ to Aoki and another with value $5$ to Snuke, the condition is satisfied, achieving the maximum possible sum of values.  \nThus, $3+5=8$ should be printed."],["3 3 0\n1 3 3\n6 2 7","\\-1\n\nHe cannot choose gifts to satisfy the condition. Note that the candidates of gifts for a person may contain multiple gifts with the same value."],["1 1 1000000000000000000\n1000000000000000000\n1000000000000000000","2000000000000000000\n\nNote that the answer may not fit into a $32$\\-bit integer type."],["8 6 1\n2 5 6 5 2 1 7 9\n7 2 5 5 2 4","14"]],"created_at":"2026-03-03 11:01:13"}}