{"problem":{"name":"[ICPC 2022 Xi'an R] Strange Sum","description":{"content":"Given a sequence $a_1, a_2, \\ldots, a_n$. You are going to select zero or more elements of $a$ so that: if you select $a_i$, then in any interval of length $i$ (formally, in $a[j, j + i - 1]$ for any","description_type":"Markdown"},"platform":"Luogu","limit":{"time_limit":1000,"memory_limit":524288},"difficulty":{"LuoguStyle":"P2"},"is_remote":true,"is_sync":true,"sync_url":null,"sign":"LGP9367"},"statements":[{"statement_type":"Markdown","content":"Given a sequence $a_1, a_2, \\ldots, a_n$.\n\nYou are going to select zero or more elements of $a$ so that: if you select $a_i$, then in any interval of length $i$ (formally, in $a[j, j + i - 1]$ for any $1 \\le j \\le n - i + 1$) you can select at most $2$ elements.\n\nCalculate the maximal sum of the elements you select.\n\n## Input\n\nThe first line contains an integer $n$ ($2 \\leq n \\leq 10^5$).\n\nThe second line contains $n$ integers $a_1, a_2, \\ldots, a_n$ ($-10^9 \\leq a_i \\leq 10^9$).\n\n## Output\n\nOutput a single integer denoting the answer.\n\n[samples]\n\n## Note\n\n**Source**: The 2022 ICPC Asia Xi'an Regional Contest Problem J.\n\n**Author**: JohnVictor.","is_translate":false,"language":"English"}],"meta":{"iden":"LGP9367","tags":["2022","O2优化","ICPC","西安"],"sample_group":[["4\n1 4 3 2\n","7\n"],["3\n-10 -10 -10\n","0"]],"created_at":"2026-03-03 11:09:25"}}