-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path262B.cpp
More file actions
47 lines (44 loc) · 665 Bytes
/
262B.cpp
File metadata and controls
47 lines (44 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<bits/stdc++.h>
using namespace std;
int a[10005];
//int flag[10005];
int main(){
int n,k;
cin>>n>>k;
//memset(flag, -1, sizeof flag);
for(int i=0; i<n; ++i)
cin>>a[i];
while(k!=0){
for(int i=n-1; i>=0; --i){
if(k==0)
break;
if(k>0 && a[i]<0){
a[i]=abs(a[i]);
//flag[i]=1;
k--;
}
}
cout<<"k= "<<k <<endl;
for(int i=0; i<n; ++i)
cout<<a[i]<<" ";
cout<<endl;
if(k!=0){
for(int i=0; i<n; ++i){
if(k==0)
break;
if(k>0){
a[i]=a[i]*(-1);
k--;
}
}
}
cout<<"k= "<<k <<endl;
for(int i=0; i<n; ++i)
cout<<a[i]<<" ";
cout<<endl;
}
int sum=0;
for(int i=0; i<n; ++i)
sum+=a[i];
cout<<sum<<"\n";
}