🏡 index : github.com/captn3m0/codechef.git

---
{"category_name":"easy","problem_code":"SIGNFLIP","problem_name":"Maximise the Subsequence Sum","problemComponents":{"constraints":"- $1 \\leq T \\leq 15$\n- $1 \\leq N \\leq 10^5$\n- $0 \\leq K \\leq N$\n- $-10^4 \\leq A_i \\leq 10^4$\n- Sum of $N$ over all test cases does not exceed $10^6$","constraintsState":true,"subtasks":"","subtasksState":true,"inputFormat":"- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains two space-separated integers $N, K$.\n- The second line of each test case contains $N$ space-separated integers $A_1, A_2,..., A_N$","inputFormatState":true,"outputFormat":"For each test case, print a single line containing one integer - the maximum sum of a subsequence you can obtain.","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"3\n6 2\n6 -10 -1 0 -4 2\n5 0\n-1 -1 -1 -1 -1\n3 3\n1 2 3\n","output":"22\n0\n6\n","explanation":"**Test case $1$:** It is optimal to multiply $-10, -4$ with $-1$ and then take the subsequence $[6, 10, 4, 2]$.\n\n**Test case $2$:** It is optimal to choose empty subsequence with a sum equal to $0$.\n\n**Test case $3$:** We can take subsequence $[1, 2, 3]$. Here, we do not multiply $-1$ with any element.","isDeleted":false}}},"video_editorial_url":"https://youtu.be/mHsupIBMr7k","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"utkarsh_adm","problem_tester":"","date_added":"26-08-2021","tags":{"0":"greedy","1":"simple","2":"start10","3":"utkarsh_adm"},"problem_difficulty_level":"Unavailable","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/SIGNFLIP","time":{"view_start_date":1630243800,"submit_start_date":1630243800,"visible_start_date":1630243800,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=SIGNFLIP","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
Chef has an array $A$ containing $N$ integers. The integers of the array can be positive, negative, or even zero.

Chef allows you to choose at most $K$ elements of the array and multiply them by $-1$.

Find the **maximum** sum of a subsequence you can obtain if you choose the elements of the subsequence optimally. 

**Note**: A sequence $a$ is a *subsequence* of a sequence $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements. For example, $[3,1]$ is a subsequence of $[3,2,1]$ and $[4,3,1]$, but not a subsequence of $[1,3,3,7]$ and $[3,10,4]$. Note that empty sequence is also a subsequence. 
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>