RAMA AND FRIEND SPOJ SOLUTION
/* RAMA AND FRIEND SOLUTION */
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,i;
cin>>t;
while(t--)
{
int n,s=0,k;
cin>>n>>k;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
while(k--)
{
a[0]*=(-1);
sort(a,a+n);
}
for(i=0;i<n;i++)
{s+=a[i];}
cout<<s<<"\n";
}
return 0;
{
int t,i;
cin>>t;
while(t--)
{
int n,s=0,k;
cin>>n>>k;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
while(k--)
{
a[0]*=(-1);
sort(a,a+n);
}
for(i=0;i<n;i++)
{s+=a[i];}
cout<<s<<"\n";
}
return 0;
}
Comments
Post a Comment