C++ solution 100% faster/memory efficient
A pure greedy question.\nAlgorithm\n1. Sort the vector\n2. Run a loop until looping variable reaches to size of vector or K.\n\t If the vector element is found 
A pure greedy question.\nAlgorithm\n1. Sort the vector\n2. Run a loop until looping variable reaches to size of vector or K.\n\t* If the vector element is found greater than or equal to 0, terminate the loop\n\t* If the vector element is found less than 0 then negate its value.\n3. Sort the value again \n4. Check if looping variable is less than K then calculate its difference. \n5. If the difference is not divisible by 2 then negate A[0].\n\n\nNote:\n1. Sorting of vector in step 3 is required to arrange back the numbers to ascending order as in previous loop the negative number was made positive too.\n2. Step 5 is checked because we can negate a number as many times possible. So we will negate the smallest number only to get maximum result.(Also twice negation of a number results to same number. So the difference is calculated and checked for its divisibility by 2.)\n3. Sorting and step 5 are showing the greedy nature of the problem.\n\n```\nclass Solution {\npublic:\n    int largestSumAfterKNegations(vector<int>& A, int K) {\n        sort(A.begin(), A.end());\n        int i, t=0, n=A.size();\n        \n        for(i=0; i < min(n, K); i++) {\n            if(A[t]>=0) break;\n            \n            else {\n                A[t]=-A[t];\n                t++;\n            }\n        }\n        \n        sort(A.begin(), A.end());\n        if(i<K) {\n            if((K-i)%2) {\n                A[0]=-A[0];\n            }\n        }\n        \n        int sum=0;\n        for(i=0; i<A.size(); i++) {\n            sum += A[i];\n        }\n        return sum;\n    }\n};\n```
[]