-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.cpp
80 lines (61 loc) · 1.65 KB
/
solution.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
// Implementation Paart
vector<int> stones(int n, int a, int b) {
vector<int> vec;
// when a == b only one value will be possible for last stone
// so if a == b only value is a * (n - 1)
if(a == b){
vec.push_back(a * (n - 1));
return vec;
}
// find max and min , in between a and b
int max, min;
if( a > b){
max = a;
min = b;
}else{
max = b;
min = a;
}
// first minimum value possible for last stone
int first = (n - 1) * min;
// last maximum value possible for last stone
int last = (n - 1) * max;
// As possible values of last stone form A.P
// with common difference = max - min
int d = max - min;
// all possible values for last stone
for(int i = first; i <= last ; i = i + d){
vec.push_back(i);
}
return vec;
}
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;
}