-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManasa and Stones
67 lines (52 loc) · 1.47 KB
/
Manasa and Stones
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
59
60
61
62
63
64
65
66
67
//the idea is to only find the final value after adding the 2 values(a,b) in all possible ways and push it into the vector.
//it is necesssary to know the min(a,b)as the returned vector must be sorted.
//also it is necessary to check if the 2 values provided are equal to ensure that duplicates are not returned in the list.
#include <bits/stdc++.h>
using namespace std;
// Complete the stones function below.
vector<int> stones(int n, int a, int b) {
vector<int> c;
int i,temp;
if(a==b){
c.push_back((n-1)*a);
return c;
}
else if(b<a){
temp = b;
b = a;
a = temp;
}
for(i=n-1;i>=0;i--){
temp = (i*a) + (n-(i+1))*b;
c.push_back(temp);
}
return c;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int T;
cin >> T;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
for (int T_itr = 0; T_itr < T; T_itr++) {
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int a;
cin >> a;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int b;
cin >> b;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
vector<int> result = stones(n, a, b);
for (int i = 0; i < result.size(); i++) {
fout << result[i];
if (i != result.size() - 1) {
fout << " ";
}
}
fout << "\n";
}
fout.close();
return 0;
}