{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eYour friend gave you a dequeue \u003cvar\u003e\\(D\\)\u003c/var\u003e as a birthday present.\u003c/p\u003e\r\n\u003cp\u003e\u003cvar\u003e\\(D\\)\u003c/var\u003e is a horizontal cylinder that contains a row of \u003cvar\u003e\\(N\\)\u003c/var\u003e jewels.\u003c/p\u003e\r\n\u003cp\u003eThe \u003cem\u003evalues\u003c/em\u003e of the jewels are \u003cvar\u003e\\(V_1, V_2, ..., V_N\\)\u003c/var\u003e from left to right. There may be jewels with negative values.\u003c/p\u003e\r\n\u003cp\u003eIn the beginning, you have no jewel in your hands.\u003c/p\u003e\r\n\u003cp\u003eYou can perform at most \u003cvar\u003e\\(K\\)\u003c/var\u003e operations on \u003cvar\u003e\\(D\\)\u003c/var\u003e, chosen from the following, at most \u003cvar\u003e\\(K\\)\u003c/var\u003e times (possibly zero):\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\r\n\u003cp\u003eOperation A: Take out the leftmost jewel contained in \u003cvar\u003e\\(D\\)\u003c/var\u003e and have it in your hand. You cannot do this operation when \u003cvar\u003e\\(D\\)\u003c/var\u003e is empty.\u003c/p\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\n\u003cp\u003eOperation B: Take out the rightmost jewel contained in \u003cvar\u003e\\(D\\)\u003c/var\u003e and have it in your hand. You cannot do this operation when \u003cvar\u003e\\(D\\)\u003c/var\u003e is empty.\u003c/p\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\n\u003cp\u003eOperation C: Choose a jewel in your hands and insert it to the left end of \u003cvar\u003e\\(D\\)\u003c/var\u003e. You cannot do this operation when you have no jewel in your hand.\u003c/p\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003e\r\n\u003cp\u003eOperation D: Choose a jewel in your hands and insert it to the right end of \u003cvar\u003e\\(D\\)\u003c/var\u003e. You cannot do this operation when you have no jewel in your hand.\u003c/p\u003e\r\n\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eFind the maximum possible sum of the values of jewels in your hands after the operations.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eAll values in input are integers.\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq N \\leq 50\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq K \\leq 100\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(-10^7 \\leq V_i \\leq 10^7\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(N\\)\u003c/var\u003e \u003cvar\u003e\\(K\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(V_1\\)\u003c/var\u003e \u003cvar\u003e\\(V_2\\)\u003c/var\u003e \u003cvar\u003e\\(...\\)\u003c/var\u003e \u003cvar\u003e\\(V_N\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003ePrint the maximum possible sum of the values of jewels in your hands after the operations.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e6 4\r\n-10 8 2 1 2 6\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e14\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eAfter the following sequence of operations, you have two jewels of values \u003cvar\u003e\\(8\\)\u003c/var\u003e and \u003cvar\u003e\\(6\\)\u003c/var\u003e in your hands for a total of \u003cvar\u003e\\(14\\)\u003c/var\u003e, which is the maximum result.\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eDo operation A. You take out the jewel of value \u003cvar\u003e\\(-10\\)\u003c/var\u003e from the left end of \u003cvar\u003e\\(D\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003eDo operation B. You take out the jewel of value \u003cvar\u003e\\(6\\)\u003c/var\u003e from the right end of \u003cvar\u003e\\(D\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003eDo operation A. You take out the jewel of value \u003cvar\u003e\\(8\\)\u003c/var\u003e from the left end of \u003cvar\u003e\\(D\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003eDo operation D. You insert the jewel of value \u003cvar\u003e\\(-10\\)\u003c/var\u003e to the right end of \u003cvar\u003e\\(D\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e6 4\r\n-6 -100 50 -2 -5 -3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e44\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 3","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e6 3\r\n-6 -100 50 -2 -5 -3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eIt is optimal to do no operation.\u003c/p\u003e\u003c/section\u003e\r\n"}}]}