fork download
  1. #include<iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. long main(){
  5. long n,k,x,i,negative; long long result;
  6. while(cin>>n>>k){
  7. long ar[100000];
  8. negative=0;
  9. for (i = 0; i <n; i++)
  10. {
  11. cin>>x;
  12. ar[i]=x; if(x<0) negative++;
  13. }
  14. while(k>0){
  15. long* pos=min_element(ar,ar+negative);
  16. if(pos!=(ar+n)){
  17. long postion=distance(ar,pos);
  18. if(ar[postion]<0)ar[postion]*=-1;else break;
  19. } else break;
  20. k--;
  21. }
  22. if(k>0 && k%2!=0) ar[0]*=-1;
  23. result=0;
  24. for (i = 0; i <n; i++) result+=ar[i];
  25. cout<<result<<endl;
  26. }
  27. return 0;
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
3 2
1 1 -1
3 2
1 1 1
3 2
-1 -1 1
3 1
-1 -1 1
17 27
257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343
69 28
-9822 -9264 -9253 -9221 -9139 -9126 -9096 -8981 -8521 -8313 -8257 -8253 -7591 -7587 -7301 -7161 -7001 -6847 -6441 -6241 -5949 -5896 -5713 -5692 -5644 -5601 -5545 -5525 -5331 -5253 -5041 -5000 -4951 -4855 -4384 -4293 -4251 -4001 -3991 -3762 -3544 -3481 -3261 -2983 -2882 -2857 -2713 -2691 -2681 -2653 -2221 -2043 -2011 -1997 -1601 -1471 -1448 -1363 -1217 -1217 -1129 -961 -926 -801 -376 -327 -305 -174 -91
compilation info
prog.cpp:4:11: error: '::main' must return 'int'
 long main(){
           ^
stdout
Standard output is empty