-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchocolate.cpp
More file actions
58 lines (51 loc) · 1.08 KB
/
chocolate.cpp
File metadata and controls
58 lines (51 loc) · 1.08 KB
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
48
49
50
51
52
53
54
55
56
57
58
//author @Nishant
//using vector
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n;
vector<int> choco;
for(int i=0; i<n; i++){
cin >> k;
choco.push_back(k);
}
cin >> k;
for(int i=0; i<k; i++){
int maxV = *max_element(choco.begin(), choco.end());
int maxPos = distance(choco.begin(), max_element(choco.begin(), choco.end()));
choco[maxPos] = sqrt(maxV);
}
cout << accumulate(choco.begin(), choco.end(), 0);
}
/*
//using array
#include<bits/stdc++.h>
using namespace std;
int elementPos(int a[], int maxV, int n){
for(int i=0; i<n; i++){
if(a[i] == maxV){
return i;
}
}
}
int main(){
int n, k;
cin >> n;
int choco[n];
for(int i=0; i<n; i++){
cin >> choco[i];
}
cin >> k;
for(int i=0; i<k; i++){
int maxV = *max_element(choco, choco+n);
int maxPos = elementPos(choco, maxV, n);
choco[maxPos] = sqrt(maxV);
}
int sum = 0;
for(int i=0; i<n; i++){
sum += choco[i];
}
cout << sum;
}
*/