output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 12;
const int maxh = 17;
const int inf = 10 * 1000;
int n;
int h[maxn];
int a, b;
int d[maxn][maxh][maxh];
pair<int, pair<int, int> > par[maxn][maxh][maxh];
vector<int> ans;
void findans(int i, int j, int k) {
pair<int, pair<int, int> > pi = par[i][j][k];
int ip = pi.first;
int jp = pi.second.first;
int kp = pi.second.second;
if (ip == -1) return;
int mv = 1;
if (ip != i) mv = d[i][j][k] - d[ip][jp][kp];
for (int t = 0; t < mv; ++t) ans.push_back(i + 1);
findans(ip, jp, kp);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 0; i < n; ++i) cin >> h[i];
if (n == 3) {
int nu = max(h[0] / b, max(h[1] / a, h[2] / b)) + 1;
cout << nu << endl;
for (int i = 0; i < nu; ++i) cout << 2 << " ";
cout << endl;
return 0;
}
h[1] -= (h[0] / b + 1) * a;
h[n - 2] -= (h[n - 1] / b + 1) * a;
h[2] -= (h[0] / b + 1) * b;
h[n - 3] -= (h[n - 1] / b + 1) * b;
if (h[1] < 0) h[1] = -1;
if (h[2] < 0) h[2] = -1;
if (h[n - 2] < 0) h[n - 2] = -1;
if (h[n - 3] < 0) h[n - 3] = -1;
for (int i = 0; i < maxn; ++i)
for (int j = 0; j < maxh; ++j)
for (int k = 0; k < maxh; ++k) d[i][j][k] = inf;
d[1][max(h[1] + 1, 0)][max(h[2] + 1, 0)] = 0;
par[1][max(h[1] + 1, 0)][max(h[2] + 1, 0)] =
pair<int, pair<int, int> >(-1, pair<int, int>(0, 0));
for (int i = 1; i < n - 1; ++i) {
for (int j = max(h[i] + 2, 1) - 1; j >= 0; --j) {
int hp1 = j - 1;
for (int j2 = max(h[i + 1] + 2, 1) - 1; j2 >= 0; --j2) {
if (d[i][j][j2] != inf) {
}
if (hp1 == -1) {
if (d[i + 1][j2][max(h[i + 2] + 1, 0)] > d[i][j][j2]) {
d[i + 1][j2][max(h[i + 2] + 1, 0)] = d[i][j][j2];
par[i + 1][j2][max(h[i + 2] + 1, 0)] =
pair<int, pair<int, int> >(i, pair<int, int>(j, j2));
}
continue;
}
if (d[i][max(j - a, 0)][max(j2 - b, 0)] > d[i][j][j2] + 1) {
d[i][max(j - a, 0)][max(j2 - b, 0)] = d[i][j][j2] + 1;
par[i][max(j - a, 0)][max(j2 - b, 0)] =
pair<int, pair<int, int> >(i, pair<int, int>(j, j2));
}
int mv = hp1 / b + 1;
if (i != n - 2) {
if (d[i + 1][max(j2 - mv * a, 0)][max(h[i + 2] + 1 - mv * b, 0)] >
d[i][j][j2] + mv) {
d[i + 1][max(j2 - mv * a, 0)][max(h[i + 2] + 1 - mv * b, 0)] =
d[i][j][j2] + mv;
par[i + 1][max(j2 - mv * a, 0)][max(h[i + 2] + 1 - mv * b, 0)] =
pair<int, pair<int, int> >(i, pair<int, int>(j, j2));
}
}
}
}
}
int mj = 0, mk = 0;
for (int j = 0; j < maxh; ++j)
for (int k = 0; k < maxh; ++k)
if (d[n - 1][j][k] < d[n - 1][mj][mk]) {
mj = j;
mk = k;
}
for (int i = 0; i < h[n - 1] / b + 1; ++i) ans.push_back(n - 1);
findans(n - 1, mj, mk);
for (int i = 0; i < h[0] / b + 1; ++i) ans.push_back(2);
reverse((ans).begin(), (ans).end());
cout << (int)(ans).size() << endl;
for (int i = 0; i < (int)(ans).size(); ++i) cout << ans[i] << " ";
cout << endl;
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 12;
const int maxh = 17;
const int inf = 10 * 1000;
int n;
int h[maxn];
int a, b;
int d[maxn][maxh][maxh];
pair<int, pair<int, int> > par[maxn][maxh][maxh];
vector<int> ans;
void findans(int i, int j, int k) {
pair<int, pair<int, int> > pi = par[i][j][k];
int ip = pi.first;
int jp = pi.second.first;
int kp = pi.second.second;
if (ip == -1) return;
int mv = 1;
if (ip != i) mv = d[i][j][k] - d[ip][jp][kp];
for (int t = 0; t < mv; ++t) ans.push_back(i + 1);
findans(ip, jp, kp);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 0; i < n; ++i) cin >> h[i];
if (n == 3) {
int nu = max(h[0] / b, max(h[1] / a, h[2] / b)) + 1;
cout << nu << endl;
for (int i = 0; i < nu; ++i) cout << 2 << " ";
cout << endl;
return 0;
}
h[1] -= (h[0] / b + 1) * a;
h[n - 2] -= (h[n - 1] / b + 1) * a;
h[2] -= (h[0] / b + 1) * b;
h[n - 3] -= (h[n - 1] / b + 1) * b;
if (h[1] < 0) h[1] = -1;
if (h[2] < 0) h[2] = -1;
if (h[n - 2] < 0) h[n - 2] = -1;
if (h[n - 3] < 0) h[n - 3] = -1;
for (int i = 0; i < maxn; ++i)
for (int j = 0; j < maxh; ++j)
for (int k = 0; k < maxh; ++k) d[i][j][k] = inf;
d[1][max(h[1] + 1, 0)][max(h[2] + 1, 0)] = 0;
par[1][max(h[1] + 1, 0)][max(h[2] + 1, 0)] =
pair<int, pair<int, int> >(-1, pair<int, int>(0, 0));
for (int i = 1; i < n - 1; ++i) {
for (int j = max(h[i] + 2, 1) - 1; j >= 0; --j) {
int hp1 = j - 1;
for (int j2 = max(h[i + 1] + 2, 1) - 1; j2 >= 0; --j2) {
if (d[i][j][j2] != inf) {
}
if (hp1 == -1) {
if (d[i + 1][j2][max(h[i + 2] + 1, 0)] > d[i][j][j2]) {
d[i + 1][j2][max(h[i + 2] + 1, 0)] = d[i][j][j2];
par[i + 1][j2][max(h[i + 2] + 1, 0)] =
pair<int, pair<int, int> >(i, pair<int, int>(j, j2));
}
continue;
}
if (d[i][max(j - a, 0)][max(j2 - b, 0)] > d[i][j][j2] + 1) {
d[i][max(j - a, 0)][max(j2 - b, 0)] = d[i][j][j2] + 1;
par[i][max(j - a, 0)][max(j2 - b, 0)] =
pair<int, pair<int, int> >(i, pair<int, int>(j, j2));
}
int mv = hp1 / b + 1;
if (i != n - 2) {
if (d[i + 1][max(j2 - mv * a, 0)][max(h[i + 2] + 1 - mv * b, 0)] >
d[i][j][j2] + mv) {
d[i + 1][max(j2 - mv * a, 0)][max(h[i + 2] + 1 - mv * b, 0)] =
d[i][j][j2] + mv;
par[i + 1][max(j2 - mv * a, 0)][max(h[i + 2] + 1 - mv * b, 0)] =
pair<int, pair<int, int> >(i, pair<int, int>(j, j2));
}
}
}
}
}
int mj = 0, mk = 0;
for (int j = 0; j < maxh; ++j)
for (int k = 0; k < maxh; ++k)
if (d[n - 1][j][k] < d[n - 1][mj][mk]) {
mj = j;
mk = k;
}
for (int i = 0; i < h[n - 1] / b + 1; ++i) ans.push_back(n - 1);
findans(n - 1, mj, mk);
for (int i = 0; i < h[0] / b + 1; ++i) ans.push_back(2);
reverse((ans).begin(), (ans).end());
cout << (int)(ans).size() << endl;
for (int i = 0; i < (int)(ans).size(); ++i) cout << ans[i] << " ";
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int MXN = 10 + 9;
int n, a, b;
int h[MXN];
int ansTime = 0x3f3f3f3f;
vector<int> ans;
vector<int> v;
void dfs(int pos, int times) {
if (times >= ansTime) return;
if (pos == n) {
if (times < ansTime) {
ansTime = times;
ans.clear();
for (unsigned int i = 0; i < v.size(); i++) ans.push_back(v[i]);
}
return;
}
if (pos == 0 || pos == n - 1) {
dfs(pos + 1, times);
return;
}
int l = ((h[pos - 1]) + b) / b,
r = max(l, max((h[pos] + a) / a, (h[pos + 1] + b) / b));
if (pos == n - 2) l = r;
for (int i = l; i <= r; i++) {
if (i < 0) continue;
for (int j = 0; j < i; j++)
v.push_back(pos + 1), h[pos - 1] -= b, h[pos] -= a, h[pos + 1] -= b;
dfs(pos + 1, times + i);
for (int j = 0; j < i; j++)
v.pop_back(), h[pos - 1] += b, h[pos] += a, h[pos + 1] += b;
}
}
void solve() {
dfs(0, 0);
printf("%d\n", (int)ans.size());
for (int i : ans) printf("%d ", i);
puts("");
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 0; i < n; i++) scanf("%d", &h[i]);
solve();
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MXN = 10 + 9;
int n, a, b;
int h[MXN];
int ansTime = 0x3f3f3f3f;
vector<int> ans;
vector<int> v;
void dfs(int pos, int times) {
if (times >= ansTime) return;
if (pos == n) {
if (times < ansTime) {
ansTime = times;
ans.clear();
for (unsigned int i = 0; i < v.size(); i++) ans.push_back(v[i]);
}
return;
}
if (pos == 0 || pos == n - 1) {
dfs(pos + 1, times);
return;
}
int l = ((h[pos - 1]) + b) / b,
r = max(l, max((h[pos] + a) / a, (h[pos + 1] + b) / b));
if (pos == n - 2) l = r;
for (int i = l; i <= r; i++) {
if (i < 0) continue;
for (int j = 0; j < i; j++)
v.push_back(pos + 1), h[pos - 1] -= b, h[pos] -= a, h[pos + 1] -= b;
dfs(pos + 1, times + i);
for (int j = 0; j < i; j++)
v.pop_back(), h[pos - 1] += b, h[pos] += a, h[pos + 1] += b;
}
}
void solve() {
dfs(0, 0);
printf("%d\n", (int)ans.size());
for (int i : ans) printf("%d ", i);
puts("");
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 0; i < n; i++) scanf("%d", &h[i]);
solve();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 10;
int a, b, h[maxN], c[maxN], res[maxN], n;
void f(int p, int lim) {
if (p == n - 1) {
for (int i = (1); i <= (n - 2); ++i)
if (h[i] >= b * (c[i - 1] + c[i + 1]) + a * c[i]) return;
throw 1;
}
for (int i = 0; i < (lim + 1); ++i) c[p] = i, f(p + 1, lim - i);
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < (n); ++i) cin >> h[i];
while (h[0] >= 0) res[1]++, h[0] -= b, h[2] -= b, h[1] -= a;
while (h[n - 1] >= 0)
res[n - 2]++, h[n - 1] -= b, h[n - 3] -= b, h[n - 2] -= a;
for (int lim = 0;; lim++) try {
f(1, lim);
} catch (int x) {
vector<int> ret;
for (int i = (1); i <= (n - 2); ++i) res[i] += c[i];
for (int i = (1); i <= (n - 2); ++i)
for (int j = 0; j < (res[i]); ++j) ret.push_back(i + 1);
n = (int)(ret).size();
cout << n << endl;
for (int i = 0; i < (n); ++i) cout << ret[i] << (i + 1 == n ? '\n' : ' ');
break;
}
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxN = 10;
int a, b, h[maxN], c[maxN], res[maxN], n;
void f(int p, int lim) {
if (p == n - 1) {
for (int i = (1); i <= (n - 2); ++i)
if (h[i] >= b * (c[i - 1] + c[i + 1]) + a * c[i]) return;
throw 1;
}
for (int i = 0; i < (lim + 1); ++i) c[p] = i, f(p + 1, lim - i);
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < (n); ++i) cin >> h[i];
while (h[0] >= 0) res[1]++, h[0] -= b, h[2] -= b, h[1] -= a;
while (h[n - 1] >= 0)
res[n - 2]++, h[n - 1] -= b, h[n - 3] -= b, h[n - 2] -= a;
for (int lim = 0;; lim++) try {
f(1, lim);
} catch (int x) {
vector<int> ret;
for (int i = (1); i <= (n - 2); ++i) res[i] += c[i];
for (int i = (1); i <= (n - 2); ++i)
for (int j = 0; j < (res[i]); ++j) ret.push_back(i + 1);
n = (int)(ret).size();
cout << n << endl;
for (int i = 0; i < (n); ++i) cout << ret[i] << (i + 1 == n ? '\n' : ' ');
break;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h[100005], path[100005];
int sol[100005];
int a, b, n, ans;
int k = 0;
void decrease(int &x, int &y, int &z) {
x -= b;
x = max(x, 0);
z -= b;
z = max(z, 0);
y -= a;
y = max(y, 0);
return;
}
void dfs(int current, int Left, int mid, int right, int anss) {
if (anss >= ans) return;
if (current == n) {
if (Left + mid + right == 0) {
if (anss < ans) {
ans = anss;
for (int(i) = (0); (i) < (anss); ++(i)) {
sol[i] = path[i];
}
}
}
return;
}
while (Left) {
decrease(Left, mid, right);
path[anss++] = current;
}
dfs(current + 1, mid, right, h[current + 2], anss);
while (mid + right) {
decrease(Left, mid, right);
path[anss++] = current;
dfs(current + 1, mid, right, h[current + 2], anss);
}
dfs(current + 1, mid, right, h[current + 2], anss);
return;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> a >> b;
for (int(i) = (1); (i) < (n + 1); ++(i)) {
cin >> h[i];
h[i]++;
}
ans = 9876543;
dfs(2, h[1], h[2], h[3], 0);
cout << ans << "\n";
for (int(i) = (0); (i) < (ans); ++(i)) {
cout << sol[i] << " ";
}
cout << "\n";
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h[100005], path[100005];
int sol[100005];
int a, b, n, ans;
int k = 0;
void decrease(int &x, int &y, int &z) {
x -= b;
x = max(x, 0);
z -= b;
z = max(z, 0);
y -= a;
y = max(y, 0);
return;
}
void dfs(int current, int Left, int mid, int right, int anss) {
if (anss >= ans) return;
if (current == n) {
if (Left + mid + right == 0) {
if (anss < ans) {
ans = anss;
for (int(i) = (0); (i) < (anss); ++(i)) {
sol[i] = path[i];
}
}
}
return;
}
while (Left) {
decrease(Left, mid, right);
path[anss++] = current;
}
dfs(current + 1, mid, right, h[current + 2], anss);
while (mid + right) {
decrease(Left, mid, right);
path[anss++] = current;
dfs(current + 1, mid, right, h[current + 2], anss);
}
dfs(current + 1, mid, right, h[current + 2], anss);
return;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> a >> b;
for (int(i) = (1); (i) < (n + 1); ++(i)) {
cin >> h[i];
h[i]++;
}
ans = 9876543;
dfs(2, h[1], h[2], h[3], 0);
cout << ans << "\n";
for (int(i) = (0); (i) < (ans); ++(i)) {
cout << sol[i] << " ";
}
cout << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, h[20] = {0}, tmp[20] = {0}, ans[20] = {0}, a, b, MIN = -1;
void f(int, int);
int main() {
int i, j, k;
cin >> n >> a >> b;
for (i = 0; i < n; i++) cin >> h[i];
f(1, 0);
cout << MIN << endl;
for (i = 0; i < n; i++)
for (j = 0; j < ans[i]; j++) cout << i + 1 << " ";
cout << endl;
return 0;
}
void f(int ind, int s) {
if (ind == n - 1) {
if (h[ind - 1] == 0) return;
int t = 0;
if (h[ind] >= 0) t = h[ind] / b + 1;
tmp[ind - 1] += t;
if (s + t < MIN || MIN == -1) {
MIN = s + t;
memcpy(ans, tmp, sizeof tmp);
}
tmp[ind - 1] -= t;
return;
}
if (h[ind - 1] >= 0) {
int t = h[ind - 1] / b + 1;
h[ind - 1] -= t * b;
h[ind] -= t * a;
h[ind + 1] -= t * b;
tmp[ind] += t;
f(ind, s + t);
h[ind - 1] += t * b;
h[ind] += t * a;
h[ind + 1] += t * b;
tmp[ind] -= t;
} else {
f(ind + 1, s);
if (h[ind] >= 0) {
h[ind] -= a;
h[ind + 1] -= b;
tmp[ind]++;
f(ind, s + 1);
h[ind] += a;
h[ind + 1] += b;
tmp[ind]--;
}
}
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, h[20] = {0}, tmp[20] = {0}, ans[20] = {0}, a, b, MIN = -1;
void f(int, int);
int main() {
int i, j, k;
cin >> n >> a >> b;
for (i = 0; i < n; i++) cin >> h[i];
f(1, 0);
cout << MIN << endl;
for (i = 0; i < n; i++)
for (j = 0; j < ans[i]; j++) cout << i + 1 << " ";
cout << endl;
return 0;
}
void f(int ind, int s) {
if (ind == n - 1) {
if (h[ind - 1] == 0) return;
int t = 0;
if (h[ind] >= 0) t = h[ind] / b + 1;
tmp[ind - 1] += t;
if (s + t < MIN || MIN == -1) {
MIN = s + t;
memcpy(ans, tmp, sizeof tmp);
}
tmp[ind - 1] -= t;
return;
}
if (h[ind - 1] >= 0) {
int t = h[ind - 1] / b + 1;
h[ind - 1] -= t * b;
h[ind] -= t * a;
h[ind + 1] -= t * b;
tmp[ind] += t;
f(ind, s + t);
h[ind - 1] += t * b;
h[ind] += t * a;
h[ind + 1] += t * b;
tmp[ind] -= t;
} else {
f(ind + 1, s);
if (h[ind] >= 0) {
h[ind] -= a;
h[ind + 1] -= b;
tmp[ind]++;
f(ind, s + 1);
h[ind] += a;
h[ind + 1] += b;
tmp[ind]--;
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int M = 5e6;
const int N = 1e2 + 5;
int n, a, b;
int h[N];
vector<int> g, v;
int ans = 1 << 30;
void dfs(int x, int now) {
if (now >= ans) return;
if (x == n) {
if (h[x] < 0) g = v, ans = min(ans, now);
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) v.push_back(x);
dfs(x + 1, now + i);
for (int j = 0; j < i; j++) v.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
signed main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < g.size(); i++) cout << g[i] << " ";
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int M = 5e6;
const int N = 1e2 + 5;
int n, a, b;
int h[N];
vector<int> g, v;
int ans = 1 << 30;
void dfs(int x, int now) {
if (now >= ans) return;
if (x == n) {
if (h[x] < 0) g = v, ans = min(ans, now);
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) v.push_back(x);
dfs(x + 1, now + i);
for (int j = 0; j < i; j++) v.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
signed main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < g.size(); i++) cout << g[i] << " ";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int M = 20;
int h[M];
int n, a, b;
int ans = 1e9;
int ansn[150], anss[150];
int ceil(int x, int y) {
if (x <= 0) return 0;
if (x % y) return x / y + 1;
return x / y;
}
void dfs(int p, int pre, int now, int pos, int num) {
int t = max(ceil(pre, b), ceil(now, a));
t = max(t, ceil(pos, b));
if (p == n - 1) {
for (int i = 1; i <= t; i++) ansn[i + num] = n - 1;
num += t;
if (num < ans) {
ans = num;
for (int i = 1; i <= num; i++) anss[i] = ansn[i];
}
return;
}
for (int i = ceil(pre, b); i <= t; i++) {
for (int j = 1; j <= i; j++) ansn[num + j] = p;
dfs(p + 1, now - i * a, pos - i * b, h[p + 2], num + i);
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
for (int i = 1; i <= n; i++) h[i]++;
dfs(2, h[1], h[2], h[3], 0);
printf("%d\n", ans);
for (int i = 1; i < ans; i++) printf("%d ", anss[i]);
printf("%d\n", anss[ans]);
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 20;
int h[M];
int n, a, b;
int ans = 1e9;
int ansn[150], anss[150];
int ceil(int x, int y) {
if (x <= 0) return 0;
if (x % y) return x / y + 1;
return x / y;
}
void dfs(int p, int pre, int now, int pos, int num) {
int t = max(ceil(pre, b), ceil(now, a));
t = max(t, ceil(pos, b));
if (p == n - 1) {
for (int i = 1; i <= t; i++) ansn[i + num] = n - 1;
num += t;
if (num < ans) {
ans = num;
for (int i = 1; i <= num; i++) anss[i] = ansn[i];
}
return;
}
for (int i = ceil(pre, b); i <= t; i++) {
for (int j = 1; j <= i; j++) ansn[num + j] = p;
dfs(p + 1, now - i * a, pos - i * b, h[p + 2], num + i);
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
for (int i = 1; i <= n; i++) h[i]++;
dfs(2, h[1], h[2], h[3], 0);
printf("%d\n", ans);
for (int i = 1; i < ans; i++) printf("%d ", anss[i]);
printf("%d\n", anss[ans]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
inline int IN() {
int x = 0, ch = getchar(), f = 1;
while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
if (ch == '-') {
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
int a, b, n, hp[11], axl[11], cnt[11], Ans = 1 << 30;
void Hit(int pos) {
cnt[pos]++;
hp[pos] -= a;
hp[pos - 1] -= b;
hp[pos + 1] -= b;
}
void DontHit(int pos) {
cnt[pos]--;
hp[pos] += a;
hp[pos - 1] += b;
hp[pos + 1] += b;
}
bool AllKill() {
for (int i = 2; i <= n; i++)
if (hp[i] >= 0) return 0;
return 1;
}
void DFS(int cs, int np) {
if (AllKill()) {
if (cs < Ans) {
Ans = cs;
memcpy(axl, cnt, sizeof cnt);
}
return;
}
for (int i = np; i <= n - 1; i++)
if (hp[i] >= 0 || hp[i - 1] >= 0 || hp[i + 1] >= 0) {
Hit(i);
DFS(cs + 1, i);
DontHit(i);
}
}
int main() {
n = IN(), a = IN(), b = IN();
for (int i = 1; i <= n; i++) hp[i] = IN();
int nc = 0;
while (hp[1] >= 0) nc++, Hit(2);
while (hp[n] >= 0) nc++, Hit(n - 1);
DFS(nc, 2);
printf("%d\n", Ans);
for (int i = 2; i <= n - 1; i++)
while (axl[i]) axl[i]--, printf("%d ", i);
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline int IN() {
int x = 0, ch = getchar(), f = 1;
while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
if (ch == '-') {
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * f;
}
int a, b, n, hp[11], axl[11], cnt[11], Ans = 1 << 30;
void Hit(int pos) {
cnt[pos]++;
hp[pos] -= a;
hp[pos - 1] -= b;
hp[pos + 1] -= b;
}
void DontHit(int pos) {
cnt[pos]--;
hp[pos] += a;
hp[pos - 1] += b;
hp[pos + 1] += b;
}
bool AllKill() {
for (int i = 2; i <= n; i++)
if (hp[i] >= 0) return 0;
return 1;
}
void DFS(int cs, int np) {
if (AllKill()) {
if (cs < Ans) {
Ans = cs;
memcpy(axl, cnt, sizeof cnt);
}
return;
}
for (int i = np; i <= n - 1; i++)
if (hp[i] >= 0 || hp[i - 1] >= 0 || hp[i + 1] >= 0) {
Hit(i);
DFS(cs + 1, i);
DontHit(i);
}
}
int main() {
n = IN(), a = IN(), b = IN();
for (int i = 1; i <= n; i++) hp[i] = IN();
int nc = 0;
while (hp[1] >= 0) nc++, Hit(2);
while (hp[n] >= 0) nc++, Hit(n - 1);
DFS(nc, 2);
printf("%d\n", Ans);
for (int i = 2; i <= n - 1; i++)
while (axl[i]) axl[i]--, printf("%d ", i);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
int h[20], p[1000], res[1000];
int ans = 1e9;
void attack(int &a, int &b, int &c) {
a -= y;
if (a < 0) a = 0;
b -= x;
if (b < 0) b = 0;
c -= y;
if (c < 0) c = 0;
}
void go(int cur, int a, int b, int c, int lvl) {
if (lvl >= ans) return;
if (cur == n) {
if (a + b + c == 0) {
ans = lvl;
for (int i = 0; i < ans; i++) res[i] = p[i];
}
return;
}
while (a > 0) {
attack(a, b, c);
p[lvl++] = cur;
}
go(cur + 1, b, c, h[cur + 2], lvl);
while (b + c > 0) {
attack(a, b, c);
p[lvl++] = cur;
go(cur + 1, b, c, h[cur + 2], lvl);
}
}
int main() {
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
go(2, h[1], h[2], h[3], 0);
printf("%d\n", ans);
for (int i = 0; i < ans; i++) {
printf("%d ", res[i]);
}
printf("\n");
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
int h[20], p[1000], res[1000];
int ans = 1e9;
void attack(int &a, int &b, int &c) {
a -= y;
if (a < 0) a = 0;
b -= x;
if (b < 0) b = 0;
c -= y;
if (c < 0) c = 0;
}
void go(int cur, int a, int b, int c, int lvl) {
if (lvl >= ans) return;
if (cur == n) {
if (a + b + c == 0) {
ans = lvl;
for (int i = 0; i < ans; i++) res[i] = p[i];
}
return;
}
while (a > 0) {
attack(a, b, c);
p[lvl++] = cur;
}
go(cur + 1, b, c, h[cur + 2], lvl);
while (b + c > 0) {
attack(a, b, c);
p[lvl++] = cur;
go(cur + 1, b, c, h[cur + 2], lvl);
}
}
int main() {
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
go(2, h[1], h[2], h[3], 0);
printf("%d\n", ans);
for (int i = 0; i < ans; i++) {
printf("%d ", res[i]);
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[110];
vector<int> G, ans;
void dfs(int u, bool hehe) {
if (u == n && hehe == false) {
if (G.size() < ans.size()) ans = G;
return;
}
int siz = 0;
if (hehe) {
while (h[u - 1] > 0)
siz++, h[u - 1] -= b, h[u] -= a, h[u + 1] -= b, G.push_back(u);
}
if (h[u] > 0) {
while (h[u] > 0) {
dfs(u + 1, true);
h[u - 1] -= b;
h[u] -= a;
h[u + 1] -= b;
siz++;
G.push_back(u);
}
}
dfs(u + 1, false);
h[u] += a * siz;
h[u + 1] += b * siz;
h[u - 1] += b * siz;
while (siz--) G.erase(G.end() - 1);
}
int main() {
int i, j;
scanf("%d %d %d", &n, &a, &b);
G.clear();
ans.clear();
for (i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
while (h[1] > 0) {
h[2] -= a;
h[1] -= b;
h[3] -= b;
ans.push_back(2);
}
while (h[n] > 0) {
h[n - 2] -= b;
h[n - 1] -= a;
h[n] -= b;
ans.push_back(n - 1);
}
G = ans;
for (i = 1; i <= 100; i++) ans.push_back(i);
dfs(2, false);
printf("%d\n", ans.size());
for (i = 0; i < ans.size(); i++)
printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[110];
vector<int> G, ans;
void dfs(int u, bool hehe) {
if (u == n && hehe == false) {
if (G.size() < ans.size()) ans = G;
return;
}
int siz = 0;
if (hehe) {
while (h[u - 1] > 0)
siz++, h[u - 1] -= b, h[u] -= a, h[u + 1] -= b, G.push_back(u);
}
if (h[u] > 0) {
while (h[u] > 0) {
dfs(u + 1, true);
h[u - 1] -= b;
h[u] -= a;
h[u + 1] -= b;
siz++;
G.push_back(u);
}
}
dfs(u + 1, false);
h[u] += a * siz;
h[u + 1] += b * siz;
h[u - 1] += b * siz;
while (siz--) G.erase(G.end() - 1);
}
int main() {
int i, j;
scanf("%d %d %d", &n, &a, &b);
G.clear();
ans.clear();
for (i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
while (h[1] > 0) {
h[2] -= a;
h[1] -= b;
h[3] -= b;
ans.push_back(2);
}
while (h[n] > 0) {
h[n - 2] -= b;
h[n - 1] -= a;
h[n] -= b;
ans.push_back(n - 1);
}
G = ans;
for (i = 1; i <= 100; i++) ans.push_back(i);
dfs(2, false);
printf("%d\n", ans.size());
for (i = 0; i < ans.size(); i++)
printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int M = 1e6 + 1;
const int base = 1e9 + 7;
const double ep = 1e-9;
int x[N];
int shot[N];
int n;
int res;
int a, b;
bool DFS(int k, int first, int la) {
if (k == 0) {
for (int i = 1; i < n + 1; i++)
if (x[i] >= 0) return false;
return true;
}
if (x[first] < 0) return DFS(k, first + 1, la);
if (first == n) {
x[first] -= b;
shot[k] = first - 1;
if (DFS(k - 1, first, la)) return true;
x[first] += b;
} else {
for (int j = max(first, la); j < first + 2; j++)
if (1 < j && j < n) {
shot[k] = j;
x[j] -= a;
x[j + 1] -= b;
x[j - 1] -= b;
if (DFS(k - 1, first, j)) return true;
x[j] += a;
x[j + 1] += b;
x[j - 1] += b;
}
}
return false;
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i < n + 1; i++) cin >> x[i];
for (res = 1;; res++) {
if (DFS(res, 1, 2)) {
cout << res << endl;
for (int j = 1; j < res + 1; j++) cout << shot[j] << " ";
return 0;
}
}
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int M = 1e6 + 1;
const int base = 1e9 + 7;
const double ep = 1e-9;
int x[N];
int shot[N];
int n;
int res;
int a, b;
bool DFS(int k, int first, int la) {
if (k == 0) {
for (int i = 1; i < n + 1; i++)
if (x[i] >= 0) return false;
return true;
}
if (x[first] < 0) return DFS(k, first + 1, la);
if (first == n) {
x[first] -= b;
shot[k] = first - 1;
if (DFS(k - 1, first, la)) return true;
x[first] += b;
} else {
for (int j = max(first, la); j < first + 2; j++)
if (1 < j && j < n) {
shot[k] = j;
x[j] -= a;
x[j + 1] -= b;
x[j - 1] -= b;
if (DFS(k - 1, first, j)) return true;
x[j] += a;
x[j + 1] += b;
x[j - 1] += b;
}
}
return false;
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i < n + 1; i++) cin >> x[i];
for (res = 1;; res++) {
if (DFS(res, 1, 2)) {
cout << res << endl;
for (int j = 1; j < res + 1; j++) cout << shot[j] << " ";
return 0;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], res = 1e9, A, B, x[100005], kq[100005], kq1[100005], dem = 0,
e[100005];
void no(int val) {
if (a[n] >= 0 || a[n - 1] >= 0 || res <= val) return;
res = val;
for (int i = 2; i <= n - 1; i++) kq[i] = x[i];
return;
}
void xuli(int i, int val) {
if (val >= res) return;
if (i == 2 || i == n - 1 || 1 == 1) {
for (int j = 0; j <= 16; j++) {
bool ok = true;
x[i] = j;
a[i - 1] -= B * j;
a[i] -= A * j;
a[i + 1] -= B * j;
if (a[i - 1] >= 0) ok = false;
if (ok == true) {
if (i == n - 1)
no(val + j);
else
xuli(i + 1, val + j);
}
a[i - 1] += B * j;
a[i] += A * j;
a[i + 1] += B * j;
}
} else {
int tg = max(e[i] / A + 1, max(e[i - 1] / B + 1, e[i + 1] / B + 1));
for (int j = 0; j <= tg; j++) {
bool ok = true;
x[i] = j;
a[i - 1] -= B * j;
a[i] -= A * j;
a[i + 1] -= B * j;
if (a[i - 1] >= 0) ok = false;
if (ok == true) {
if (i == n - 1)
no(val + j);
else
xuli(i + 1, val + j);
}
a[i - 1] += B * j;
a[i] += A * j;
a[i + 1] += B * j;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; i++) cin >> a[i], e[i] = a[i];
xuli(2, 0);
cout << res << '\n';
for (int i = 2; i <= n - 1; i++)
for (int j = 1; j <= kq[i]; j++) kq1[++dem] = i;
for (int i = 1; i <= dem; i++) cout << kq1[i] << " ";
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], res = 1e9, A, B, x[100005], kq[100005], kq1[100005], dem = 0,
e[100005];
void no(int val) {
if (a[n] >= 0 || a[n - 1] >= 0 || res <= val) return;
res = val;
for (int i = 2; i <= n - 1; i++) kq[i] = x[i];
return;
}
void xuli(int i, int val) {
if (val >= res) return;
if (i == 2 || i == n - 1 || 1 == 1) {
for (int j = 0; j <= 16; j++) {
bool ok = true;
x[i] = j;
a[i - 1] -= B * j;
a[i] -= A * j;
a[i + 1] -= B * j;
if (a[i - 1] >= 0) ok = false;
if (ok == true) {
if (i == n - 1)
no(val + j);
else
xuli(i + 1, val + j);
}
a[i - 1] += B * j;
a[i] += A * j;
a[i + 1] += B * j;
}
} else {
int tg = max(e[i] / A + 1, max(e[i - 1] / B + 1, e[i + 1] / B + 1));
for (int j = 0; j <= tg; j++) {
bool ok = true;
x[i] = j;
a[i - 1] -= B * j;
a[i] -= A * j;
a[i + 1] -= B * j;
if (a[i - 1] >= 0) ok = false;
if (ok == true) {
if (i == n - 1)
no(val + j);
else
xuli(i + 1, val + j);
}
a[i - 1] += B * j;
a[i] += A * j;
a[i + 1] += B * j;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; i++) cin >> a[i], e[i] = a[i];
xuli(2, 0);
cout << res << '\n';
for (int i = 2; i <= n - 1; i++)
for (int j = 1; j <= kq[i]; j++) kq1[++dem] = i;
for (int i = 1; i <= dem; i++) cout << kq1[i] << " ";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 20, Wf = 150;
int n, a, b, h[N], f[N][N][N];
pair<int, int> g[N][N][N];
vector<int> path;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = (0); i < (n); ++i) {
cin >> h[i];
}
for (int p = (0); p < (n + 1); ++p) {
for (int i = (0); i < (N); ++i) {
for (int j = (0); j < (N); ++j) {
f[p][i][j] = Wf;
}
}
}
f[0][0][0] = 0;
for (int p = (0); p < (n - 2); ++p) {
for (int i = (0); i < (N); ++i) {
for (int j = (0); j < (N); ++j)
if (f[p][i][j] != Wf) {
for (int x = (0); x < (N); ++x) {
if (i + x * b > h[p]) {
int I = min(j + x * a, N - 1);
int J = min(x * b, N - 1);
if (f[p][i][j] + x < f[p + 1][I][J]) {
f[p + 1][I][J] = f[p][i][j] + x;
g[p + 1][I][J].first = i;
g[p + 1][I][J].second = j;
}
}
}
}
}
}
int res = Wf;
pair<int, int> now;
for (int i = (0); i < (N); ++i) {
for (int j = (0); j < (N); ++j) {
if (i > h[n - 2] and j > h[n - 1]) {
if (f[n - 2][i][j] < res) {
res = f[n - 2][i][j];
now.first = i, now.second = j;
}
}
}
}
for (int p = (n - 2) - 1; p >= (0); --p) {
int &i = now.first, &j = now.second;
int I = g[p + 1][i][j].first, J = g[p + 1][i][j].second;
for (int x = (0); x < (f[p + 1][i][j] - f[p][I][J]); ++x) {
path.push_back(p);
}
i = I, j = J;
}
cout << res << '\n';
for (const int &i : path) {
cout << i + 2 << ' ';
}
cout << '\n';
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 20, Wf = 150;
int n, a, b, h[N], f[N][N][N];
pair<int, int> g[N][N][N];
vector<int> path;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = (0); i < (n); ++i) {
cin >> h[i];
}
for (int p = (0); p < (n + 1); ++p) {
for (int i = (0); i < (N); ++i) {
for (int j = (0); j < (N); ++j) {
f[p][i][j] = Wf;
}
}
}
f[0][0][0] = 0;
for (int p = (0); p < (n - 2); ++p) {
for (int i = (0); i < (N); ++i) {
for (int j = (0); j < (N); ++j)
if (f[p][i][j] != Wf) {
for (int x = (0); x < (N); ++x) {
if (i + x * b > h[p]) {
int I = min(j + x * a, N - 1);
int J = min(x * b, N - 1);
if (f[p][i][j] + x < f[p + 1][I][J]) {
f[p + 1][I][J] = f[p][i][j] + x;
g[p + 1][I][J].first = i;
g[p + 1][I][J].second = j;
}
}
}
}
}
}
int res = Wf;
pair<int, int> now;
for (int i = (0); i < (N); ++i) {
for (int j = (0); j < (N); ++j) {
if (i > h[n - 2] and j > h[n - 1]) {
if (f[n - 2][i][j] < res) {
res = f[n - 2][i][j];
now.first = i, now.second = j;
}
}
}
}
for (int p = (n - 2) - 1; p >= (0); --p) {
int &i = now.first, &j = now.second;
int I = g[p + 1][i][j].first, J = g[p + 1][i][j].second;
for (int x = (0); x < (f[p + 1][i][j] - f[p][I][J]); ++x) {
path.push_back(p);
}
i = I, j = J;
}
cout << res << '\n';
for (const int &i : path) {
cout << i + 2 << ' ';
}
cout << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, ans, h[20], buffer[200], res[200];
inline int d(int a, int b) {
if (a < 0)
return a / b - 1;
else
return a / b + 1;
}
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[n] < 0) {
ans = times;
memcpy(res, buffer, ans * sizeof(int));
}
return;
}
int maxi = max(d(max(h[x - 1], h[x + 1]), b), d(h[x], a));
for (int i = max(0, d(h[x - 1], b)); i <= maxi; ++i) {
h[x - 1] -= i * b;
h[x] -= i * a;
h[x + 1] -= i * b;
for (int j = 0; j < i; ++j) buffer[times++] = x;
dfs(x + 1, times);
h[x - 1] += i * b;
h[x] += i * a;
h[x + 1] += i * b;
times -= i;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) cin >> h[i];
ans = 200;
dfs(2, 0);
cout << ans << '\n';
for (int i = 0; i < ans; ++i) cout << res[i] << ' ';
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, ans, h[20], buffer[200], res[200];
inline int d(int a, int b) {
if (a < 0)
return a / b - 1;
else
return a / b + 1;
}
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[n] < 0) {
ans = times;
memcpy(res, buffer, ans * sizeof(int));
}
return;
}
int maxi = max(d(max(h[x - 1], h[x + 1]), b), d(h[x], a));
for (int i = max(0, d(h[x - 1], b)); i <= maxi; ++i) {
h[x - 1] -= i * b;
h[x] -= i * a;
h[x + 1] -= i * b;
for (int j = 0; j < i; ++j) buffer[times++] = x;
dfs(x + 1, times);
h[x - 1] += i * b;
h[x] += i * a;
h[x + 1] += i * b;
times -= i;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) cin >> h[i];
ans = 200;
dfs(2, 0);
cout << ans << '\n';
for (int i = 0; i < ans; ++i) cout << res[i] << ' ';
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h[20], hit[20], tem[20];
int n, a, b;
bool done;
void get(int ind, int rem) {
if (done) return;
if (ind == n - 1) {
bool f = 1;
for (int i = 1; i < n - 1; i++) {
if (h[i] >= tem[i - 1] * b + tem[i + 1] * b + tem[i] * a) {
f = 0;
break;
}
}
if (f) {
for (int i = 0; i < n; i++) {
hit[i] += tem[i];
}
done = true;
}
return;
}
for (int i = 0; i <= rem; i++) {
tem[ind] = i;
get(ind + 1, rem - i);
if (done) break;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) scanf("%d", &h[i]);
int tot = 0;
while (h[0] >= 0) h[0] -= b, h[1] -= a, h[2] -= b, hit[1]++, tot++;
while (h[n - 1] >= 0)
h[n - 1] -= b, h[n - 2] -= a, h[n - 3] -= b, hit[n - 2]++, tot++;
done = 0;
for (int s = 0;; s++) {
get(1, s);
if (done) {
printf("%d\n", tot + s);
string s = "";
for (int i = 0; i < n; i++)
if (hit[i] > 0)
for (int j = 0; j < hit[i]; j++) {
printf("%s%d", s.c_str(), i + 1);
s = " ";
}
cout << endl;
break;
}
}
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h[20], hit[20], tem[20];
int n, a, b;
bool done;
void get(int ind, int rem) {
if (done) return;
if (ind == n - 1) {
bool f = 1;
for (int i = 1; i < n - 1; i++) {
if (h[i] >= tem[i - 1] * b + tem[i + 1] * b + tem[i] * a) {
f = 0;
break;
}
}
if (f) {
for (int i = 0; i < n; i++) {
hit[i] += tem[i];
}
done = true;
}
return;
}
for (int i = 0; i <= rem; i++) {
tem[ind] = i;
get(ind + 1, rem - i);
if (done) break;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) scanf("%d", &h[i]);
int tot = 0;
while (h[0] >= 0) h[0] -= b, h[1] -= a, h[2] -= b, hit[1]++, tot++;
while (h[n - 1] >= 0)
h[n - 1] -= b, h[n - 2] -= a, h[n - 3] -= b, hit[n - 2]++, tot++;
done = 0;
for (int s = 0;; s++) {
get(1, s);
if (done) {
printf("%d\n", tot + s);
string s = "";
for (int i = 0; i < n; i++)
if (hit[i] > 0)
for (int j = 0; j < hit[i]; j++) {
printf("%s%d", s.c_str(), i + 1);
s = " ";
}
cout << endl;
break;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct state {
int id, h1, h2, h3;
state() {}
state(const int &i, const int &j, const int &k, const int &l) {
id = i;
h1 = j;
h2 = k;
h3 = l;
}
bool operator!=(const state &x) const {
if (id != x.id) return (true);
if (h1 != x.h1) return (true);
if (h2 != x.h2) return (true);
if (h3 != x.h3) return (true);
return (false);
}
};
int hp[21];
int c[13][21][21][21];
int l[13][21][21][21];
pair<state, int> t[13][21][21][21];
queue<state> q;
vector<int> trc, pre;
int n, a, b;
state fin, sta;
int max(const int &x, const int &y) {
if (x > y)
return (x);
else
return (y);
}
state next(const state &x, const int &i) {
int j = x.h1;
int k = x.h2;
int l = x.h3;
if (i == 0) {
j = j - a;
k = k - b;
} else {
j = j - b;
k = k - a;
l = l - b;
}
if (j > 0) return (state(x.id, j, max(k, 0), max(l, 0)));
if (k > 0) return (state(x.id + 1, k, max(l, 0), hp[x.id + 3]));
if (l > 0) return (state(x.id + 2, l, hp[x.id + 3], hp[x.id + 4]));
return (state(x.id + 3, hp[x.id + 3], hp[x.id + 4], hp[x.id + 5]));
}
void init(void) {
scanf("%d", &n);
scanf("%d", &a);
scanf("%d", &b);
int i;
for (i = 1; i <= n; i = i + 1) {
scanf("%d", &hp[i]);
hp[i]++;
}
if (n == 3) {
while (hp[1] > 0 || hp[2] > 0 || hp[3] > 0) {
pre.push_back(2);
hp[1] -= b;
hp[2] -= a;
hp[3] -= b;
}
printf("%d\n", pre.size());
for (i = 0; i < pre.size(); i = i + 1) printf("%d ", pre[i]);
exit(0);
}
while (hp[1] > 0) {
pre.push_back(2);
hp[1] -= b;
hp[2] -= a;
hp[3] -= b;
}
if (hp[1] < 0) hp[1] = 0;
if (hp[2] < 0) hp[2] = 0;
if (hp[3] < 0) hp[3] = 0;
while (hp[n] > 0) {
pre.push_back(n - 1);
hp[n] -= b;
hp[n - 1] -= a;
hp[n - 2] -= b;
}
if (hp[n] < 0) hp[n] = 0;
if (hp[n - 1] < 0) hp[n - 1] = 0;
if (hp[n - 2] < 0) hp[n - 2] = 0;
for (i = 1; i <= n; i = i + 1)
if (hp[i] > 0) {
sta = state(i, hp[i], hp[i + 1], hp[i + 2]);
break;
}
}
void BFS(void) {
while (!q.empty()) q.pop();
state u, v;
int i;
c[sta.id][sta.h1][sta.h2][sta.h3] = 1;
q.push(sta);
while (!q.empty()) {
u = q.front();
q.pop();
if (u.h1 == 0 && u.h2 == 0 && u.h3 == 0) {
fin = u;
return;
}
for (i = 0; i < 2; i = i + 1) {
v = next(u, i);
if (c[v.id][v.h1][v.h2][v.h3] == 0) {
c[v.id][v.h1][v.h2][v.h3] = 1;
l[v.id][v.h1][v.h2][v.h3] = l[u.id][u.h1][u.h2][u.h3] + 1;
t[v.id][v.h1][v.h2][v.h3] = pair<state, int>(u, u.id + i);
q.push(v);
}
}
}
exit(150913);
}
void trace(void) {
state cur;
cur = fin;
while (cur != sta) {
trc.push_back(t[cur.id][cur.h1][cur.h2][cur.h3].second);
cur = t[cur.id][cur.h1][cur.h2][cur.h3].first;
}
printf("%d\n", pre.size() + trc.size());
int i;
for (i = 0; i < pre.size(); i = i + 1) printf("%d ", pre[i]);
for (i = 0; i < trc.size(); i = i + 1) printf("%d ", trc[i]);
}
int main(void) {
init();
BFS();
trace();
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct state {
int id, h1, h2, h3;
state() {}
state(const int &i, const int &j, const int &k, const int &l) {
id = i;
h1 = j;
h2 = k;
h3 = l;
}
bool operator!=(const state &x) const {
if (id != x.id) return (true);
if (h1 != x.h1) return (true);
if (h2 != x.h2) return (true);
if (h3 != x.h3) return (true);
return (false);
}
};
int hp[21];
int c[13][21][21][21];
int l[13][21][21][21];
pair<state, int> t[13][21][21][21];
queue<state> q;
vector<int> trc, pre;
int n, a, b;
state fin, sta;
int max(const int &x, const int &y) {
if (x > y)
return (x);
else
return (y);
}
state next(const state &x, const int &i) {
int j = x.h1;
int k = x.h2;
int l = x.h3;
if (i == 0) {
j = j - a;
k = k - b;
} else {
j = j - b;
k = k - a;
l = l - b;
}
if (j > 0) return (state(x.id, j, max(k, 0), max(l, 0)));
if (k > 0) return (state(x.id + 1, k, max(l, 0), hp[x.id + 3]));
if (l > 0) return (state(x.id + 2, l, hp[x.id + 3], hp[x.id + 4]));
return (state(x.id + 3, hp[x.id + 3], hp[x.id + 4], hp[x.id + 5]));
}
void init(void) {
scanf("%d", &n);
scanf("%d", &a);
scanf("%d", &b);
int i;
for (i = 1; i <= n; i = i + 1) {
scanf("%d", &hp[i]);
hp[i]++;
}
if (n == 3) {
while (hp[1] > 0 || hp[2] > 0 || hp[3] > 0) {
pre.push_back(2);
hp[1] -= b;
hp[2] -= a;
hp[3] -= b;
}
printf("%d\n", pre.size());
for (i = 0; i < pre.size(); i = i + 1) printf("%d ", pre[i]);
exit(0);
}
while (hp[1] > 0) {
pre.push_back(2);
hp[1] -= b;
hp[2] -= a;
hp[3] -= b;
}
if (hp[1] < 0) hp[1] = 0;
if (hp[2] < 0) hp[2] = 0;
if (hp[3] < 0) hp[3] = 0;
while (hp[n] > 0) {
pre.push_back(n - 1);
hp[n] -= b;
hp[n - 1] -= a;
hp[n - 2] -= b;
}
if (hp[n] < 0) hp[n] = 0;
if (hp[n - 1] < 0) hp[n - 1] = 0;
if (hp[n - 2] < 0) hp[n - 2] = 0;
for (i = 1; i <= n; i = i + 1)
if (hp[i] > 0) {
sta = state(i, hp[i], hp[i + 1], hp[i + 2]);
break;
}
}
void BFS(void) {
while (!q.empty()) q.pop();
state u, v;
int i;
c[sta.id][sta.h1][sta.h2][sta.h3] = 1;
q.push(sta);
while (!q.empty()) {
u = q.front();
q.pop();
if (u.h1 == 0 && u.h2 == 0 && u.h3 == 0) {
fin = u;
return;
}
for (i = 0; i < 2; i = i + 1) {
v = next(u, i);
if (c[v.id][v.h1][v.h2][v.h3] == 0) {
c[v.id][v.h1][v.h2][v.h3] = 1;
l[v.id][v.h1][v.h2][v.h3] = l[u.id][u.h1][u.h2][u.h3] + 1;
t[v.id][v.h1][v.h2][v.h3] = pair<state, int>(u, u.id + i);
q.push(v);
}
}
}
exit(150913);
}
void trace(void) {
state cur;
cur = fin;
while (cur != sta) {
trc.push_back(t[cur.id][cur.h1][cur.h2][cur.h3].second);
cur = t[cur.id][cur.h1][cur.h2][cur.h3].first;
}
printf("%d\n", pre.size() + trc.size());
int i;
for (i = 0; i < pre.size(); i = i + 1) printf("%d ", pre[i]);
for (i = 0; i < trc.size(); i = i + 1) printf("%d ", trc[i]);
}
int main(void) {
init();
BFS();
trace();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int cas = 1, T;
int n, a, b, h[12], hit[12], ans[12], minhit;
void dfs(int x, int sum) {
if (x == n) {
if (sum <= minhit) {
memcpy(ans, hit, sizeof(ans));
minhit = sum;
}
return;
}
if (h[x] < 0 && h[x - 1] < 0) {
dfs(x + 1, sum);
return;
}
int beg = h[x - 1] / b + 1;
if (h[x - 1] < 0) beg = 0;
int end = max(beg, h[x] / a + 1);
for (int i = beg; i <= end; i++) {
h[x - 1] -= i * b;
h[x] -= i * a;
h[x + 1] -= i * b;
hit[x] += i;
dfs(x + 1, sum + i);
h[x - 1] += i * b;
h[x] += i * a;
h[x + 1] += i * b;
hit[x] -= i;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
memset(h, 0, sizeof(h));
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= n; i++) scanf("%d", h + i);
if (h[1] >= 0) {
hit[2] = h[1] / b + 1;
h[1] -= hit[2] * b;
h[2] -= hit[2] * a;
h[3] -= hit[2] * b;
}
if (h[n] >= 0) {
int x = h[n] / b + 1;
hit[n - 1] += x;
h[n] -= x * b;
h[n - 1] -= x * a;
h[n - 2] -= x * b;
}
minhit = 0x3f3f3f3f;
dfs(2, hit[2] + (n - 1 != 2) * hit[n - 1]);
printf("%d\n", minhit);
for (int i = 2; i < n; i++)
while (ans[i]--) printf("%d%c", i, i == n - 1 && !ans[i] ? '\n' : ' ');
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int cas = 1, T;
int n, a, b, h[12], hit[12], ans[12], minhit;
void dfs(int x, int sum) {
if (x == n) {
if (sum <= minhit) {
memcpy(ans, hit, sizeof(ans));
minhit = sum;
}
return;
}
if (h[x] < 0 && h[x - 1] < 0) {
dfs(x + 1, sum);
return;
}
int beg = h[x - 1] / b + 1;
if (h[x - 1] < 0) beg = 0;
int end = max(beg, h[x] / a + 1);
for (int i = beg; i <= end; i++) {
h[x - 1] -= i * b;
h[x] -= i * a;
h[x + 1] -= i * b;
hit[x] += i;
dfs(x + 1, sum + i);
h[x - 1] += i * b;
h[x] += i * a;
h[x + 1] += i * b;
hit[x] -= i;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
memset(h, 0, sizeof(h));
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= n; i++) scanf("%d", h + i);
if (h[1] >= 0) {
hit[2] = h[1] / b + 1;
h[1] -= hit[2] * b;
h[2] -= hit[2] * a;
h[3] -= hit[2] * b;
}
if (h[n] >= 0) {
int x = h[n] / b + 1;
hit[n - 1] += x;
h[n] -= x * b;
h[n - 1] -= x * a;
h[n - 2] -= x * b;
}
minhit = 0x3f3f3f3f;
dfs(2, hit[2] + (n - 1 != 2) * hit[n - 1]);
printf("%d\n", minhit);
for (int i = 2; i < n; i++)
while (ans[i]--) printf("%d%c", i, i == n - 1 && !ans[i] ? '\n' : ' ');
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int X = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') X = (X << 3) + (X << 1) + c - '0', c = getchar();
return X * w;
}
int h[20];
int a, b;
int n;
int ans = 2147483647;
int sta[1010], top = 0;
int ans_op[1010], s_op = 0;
inline void Dfs(int p, int s) {
if (s >= ans) return;
if (p == n) {
if (h[n] < 0 && s < ans) {
ans = s;
memcpy(ans_op, sta, sizeof(ans_op));
s_op = ans;
}
return;
}
int End_ = max(max(h[p - 1] / b, h[p + 1] / b), h[p] / a) + 1;
for (register int i = 0; i <= End_; i++) {
if (h[p - 1] - b * i < 0) {
h[p - 1] -= b * i, h[p] -= a * i, h[p + 1] -= b * i;
for (register int j = 1; j <= i; j++) sta[++top] = p;
Dfs(p + 1, s + i);
h[p - 1] += b * i, h[p] += a * i, h[p + 1] += b * i;
for (register int j = 1; j <= i; j++) top--;
}
}
}
int main() {
n = read(), a = read(), b = read();
for (register int i = 1; i <= n; i++) h[i] = read();
Dfs(2, 0);
printf("%d\n", ans);
for (register int i = 1; i <= s_op; i++) printf("%d ", ans_op[i]);
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int X = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') X = (X << 3) + (X << 1) + c - '0', c = getchar();
return X * w;
}
int h[20];
int a, b;
int n;
int ans = 2147483647;
int sta[1010], top = 0;
int ans_op[1010], s_op = 0;
inline void Dfs(int p, int s) {
if (s >= ans) return;
if (p == n) {
if (h[n] < 0 && s < ans) {
ans = s;
memcpy(ans_op, sta, sizeof(ans_op));
s_op = ans;
}
return;
}
int End_ = max(max(h[p - 1] / b, h[p + 1] / b), h[p] / a) + 1;
for (register int i = 0; i <= End_; i++) {
if (h[p - 1] - b * i < 0) {
h[p - 1] -= b * i, h[p] -= a * i, h[p + 1] -= b * i;
for (register int j = 1; j <= i; j++) sta[++top] = p;
Dfs(p + 1, s + i);
h[p - 1] += b * i, h[p] += a * i, h[p + 1] += b * i;
for (register int j = 1; j <= i; j++) top--;
}
}
}
int main() {
n = read(), a = read(), b = read();
for (register int i = 1; i <= n; i++) h[i] = read();
Dfs(2, 0);
printf("%d\n", ans);
for (register int i = 1; i <= s_op; i++) printf("%d ", ans_op[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
int n, a, b, h[20];
int dp[20][20][20], g[20][20][20];
inline int min(int x, int y) { return x < y ? x : y; }
inline int max(int x, int y) { return x > y ? x : y; }
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
memset(dp, 0x3f, sizeof(dp));
for (int i = 0; i <= 15; i++)
if (b * i >= h[1]) dp[2][0][i] = i;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++)
for (int l = 0; l <= 15; l++)
if (a * j + b * (l + k) >= h[i - 1])
if (dp[i - 1][l][j] + k < dp[i][j][k])
dp[i][j][k] = dp[i - 1][l][j] + k, g[i][j][k] = l;
int ans = 0;
for (int i = 1; i <= 15; i++)
if (dp[n][i][0] + max(0, (h[n] - i * b + b - 1) / b) <
dp[n][ans][0] + max(0, (h[n] - ans * b + b - 1) / b))
ans = i;
printf("%d\n", dp[n][ans][0] + max(0, (h[n] - ans * b + b - 1) / b));
for (int t = 1; t <= max(0, (h[n] - ans * b + b - 1) / b); t++)
printf("%d ", n - 1);
for (int i = n, j = ans, k = 0; i >= 2;) {
for (int t = 1; t <= k; t++) printf("%d ", i);
int l = g[i][j][k];
i--, k = j, j = l;
}
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
int n, a, b, h[20];
int dp[20][20][20], g[20][20][20];
inline int min(int x, int y) { return x < y ? x : y; }
inline int max(int x, int y) { return x > y ? x : y; }
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
memset(dp, 0x3f, sizeof(dp));
for (int i = 0; i <= 15; i++)
if (b * i >= h[1]) dp[2][0][i] = i;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++)
for (int l = 0; l <= 15; l++)
if (a * j + b * (l + k) >= h[i - 1])
if (dp[i - 1][l][j] + k < dp[i][j][k])
dp[i][j][k] = dp[i - 1][l][j] + k, g[i][j][k] = l;
int ans = 0;
for (int i = 1; i <= 15; i++)
if (dp[n][i][0] + max(0, (h[n] - i * b + b - 1) / b) <
dp[n][ans][0] + max(0, (h[n] - ans * b + b - 1) / b))
ans = i;
printf("%d\n", dp[n][ans][0] + max(0, (h[n] - ans * b + b - 1) / b));
for (int t = 1; t <= max(0, (h[n] - ans * b + b - 1) / b); t++)
printf("%d ", n - 1);
for (int i = n, j = ans, k = 0; i >= 2;) {
for (int t = 1; t <= k; t++) printf("%d ", i);
int l = g[i][j][k];
i--, k = j, j = l;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7f7f7f7f;
const double eps = 1e-8;
const double PIE = acos(-1.0);
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int fx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int fy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void openfile() {
freopen("data.in", "rb", stdin);
freopen("data.out", "wb", stdout);
}
int n, a, b;
int h[15];
int ans, temp[100], path[100];
int check(int x) {
if (x <= 0)
return 0;
else
return (x - 1) / b + 1;
}
int check2(int x, int y) {
x = x <= 0 ? 0 : (x - 1) / a + 1;
y = y <= 0 ? 0 : (y - 1) / b + 1;
return x > y ? x : y;
}
void dfs(int num, int cnt) {
if (cnt >= ans) return;
if (num >= n) {
int i;
for (i = 2; i <= n - 1; i++)
if (h[i] > 0) return;
if (cnt < ans) {
ans = cnt;
for (i = 1; i <= n; i++) temp[i] = path[i];
return;
}
}
for (int i = 2; i <= num - 2; i++)
if (h[i] > 0) return;
for (int i = check(h[num - 1]); i <= check2(h[num], h[num + 1]); i++) {
h[num] -= i * a;
h[num - 1] -= i * b;
h[num + 1] -= i * b;
path[num] = i;
dfs(num + 1, cnt + i);
h[num] += i * a;
h[num - 1] += i * b;
h[num + 1] += i * b;
path[num] = -1;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = (1); i <= (n); i++) {
scanf("%d", &h[i]);
h[i]++;
}
int cnta = 0, cntb = 0;
while (h[1] > 0) {
h[2] -= a;
h[3] -= b;
h[1] -= b;
cnta++;
}
while (h[n] > 0) {
h[n - 1] -= a;
h[n] -= b;
h[n - 2] -= b;
cntb++;
}
memset(path, -1, sizeof(path));
ans = INF;
for (int i = (2); i <= (n - 1); i++) {
if (h[i] > 0) {
dfs(i, 0);
break;
}
}
if (ans == INF)
printf("%d\n", cnta + cntb);
else
printf("%d\n", cnta + cntb + ans);
for (int i = 0; i < cnta; i++) printf("%d ", 2);
for (int i = 0; i < cntb; i++) printf("%d ", n - 1);
if (ans != INF)
for (int i = 1; i <= n; i++)
if (temp[i] != -1) {
for (int j = 0; j < temp[i]; j++) printf("%d ", i);
}
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7f7f7f7f;
const double eps = 1e-8;
const double PIE = acos(-1.0);
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int fx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int fy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void openfile() {
freopen("data.in", "rb", stdin);
freopen("data.out", "wb", stdout);
}
int n, a, b;
int h[15];
int ans, temp[100], path[100];
int check(int x) {
if (x <= 0)
return 0;
else
return (x - 1) / b + 1;
}
int check2(int x, int y) {
x = x <= 0 ? 0 : (x - 1) / a + 1;
y = y <= 0 ? 0 : (y - 1) / b + 1;
return x > y ? x : y;
}
void dfs(int num, int cnt) {
if (cnt >= ans) return;
if (num >= n) {
int i;
for (i = 2; i <= n - 1; i++)
if (h[i] > 0) return;
if (cnt < ans) {
ans = cnt;
for (i = 1; i <= n; i++) temp[i] = path[i];
return;
}
}
for (int i = 2; i <= num - 2; i++)
if (h[i] > 0) return;
for (int i = check(h[num - 1]); i <= check2(h[num], h[num + 1]); i++) {
h[num] -= i * a;
h[num - 1] -= i * b;
h[num + 1] -= i * b;
path[num] = i;
dfs(num + 1, cnt + i);
h[num] += i * a;
h[num - 1] += i * b;
h[num + 1] += i * b;
path[num] = -1;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = (1); i <= (n); i++) {
scanf("%d", &h[i]);
h[i]++;
}
int cnta = 0, cntb = 0;
while (h[1] > 0) {
h[2] -= a;
h[3] -= b;
h[1] -= b;
cnta++;
}
while (h[n] > 0) {
h[n - 1] -= a;
h[n] -= b;
h[n - 2] -= b;
cntb++;
}
memset(path, -1, sizeof(path));
ans = INF;
for (int i = (2); i <= (n - 1); i++) {
if (h[i] > 0) {
dfs(i, 0);
break;
}
}
if (ans == INF)
printf("%d\n", cnta + cntb);
else
printf("%d\n", cnta + cntb + ans);
for (int i = 0; i < cnta; i++) printf("%d ", 2);
for (int i = 0; i < cntb; i++) printf("%d ", n - 1);
if (ans != INF)
for (int i = 1; i <= n; i++)
if (temp[i] != -1) {
for (int j = 0; j < temp[i]; j++) printf("%d ", i);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7f7f7f7f;
const double eps = 1e-8;
const double PIE = acos(-1.0);
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int fx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int fy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void openfile() {
freopen("data.in", "rb", stdin);
freopen("data.out", "wb", stdout);
}
int n, a, b;
int h[15];
int ans, temp[100], path[100];
int check(int x) {
if (x <= 0)
return 0;
else
return (x - 1) / b + 1;
}
void dfs(int num, int cnt) {
if (cnt >= ans) return;
if (num >= n) {
int i;
for (i = 2; i <= n - 1; i++)
if (h[i] > 0) return;
if (cnt < ans) {
ans = cnt;
for (i = 1; i <= n; i++) temp[i] = path[i];
return;
}
}
for (int i = 2; i <= num - 2; i++)
if (h[i] > 0) return;
for (int i = check(h[num - 1]); i <= 16; i++) {
h[num] -= i * a;
h[num - 1] -= i * b;
h[num + 1] -= i * b;
path[num] = i;
dfs(num + 1, cnt + i);
h[num] += i * a;
h[num - 1] += i * b;
h[num + 1] += i * b;
path[num] = -1;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = (1); i <= (n); i++) {
scanf("%d", &h[i]);
h[i]++;
}
int cnta = 0, cntb = 0;
while (h[1] > 0) {
h[2] -= a;
h[3] -= b;
h[1] -= b;
cnta++;
}
while (h[n] > 0) {
h[n - 1] -= a;
h[n] -= b;
h[n - 2] -= b;
cntb++;
}
memset(path, -1, sizeof(path));
ans = INF;
for (int i = (2); i <= (n - 1); i++) {
if (h[i] > 0) {
dfs(i, 0);
break;
}
}
if (ans == INF)
printf("%d\n", cnta + cntb);
else
printf("%d\n", cnta + cntb + ans);
for (int i = 0; i < cnta; i++) printf("%d ", 2);
for (int i = 0; i < cntb; i++) printf("%d ", n - 1);
if (ans != INF)
for (int i = 1; i <= n; i++)
if (temp[i] != -1) {
for (int j = 0; j < temp[i]; j++) printf("%d ", i);
}
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7f7f7f7f;
const double eps = 1e-8;
const double PIE = acos(-1.0);
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int fx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int fy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void openfile() {
freopen("data.in", "rb", stdin);
freopen("data.out", "wb", stdout);
}
int n, a, b;
int h[15];
int ans, temp[100], path[100];
int check(int x) {
if (x <= 0)
return 0;
else
return (x - 1) / b + 1;
}
void dfs(int num, int cnt) {
if (cnt >= ans) return;
if (num >= n) {
int i;
for (i = 2; i <= n - 1; i++)
if (h[i] > 0) return;
if (cnt < ans) {
ans = cnt;
for (i = 1; i <= n; i++) temp[i] = path[i];
return;
}
}
for (int i = 2; i <= num - 2; i++)
if (h[i] > 0) return;
for (int i = check(h[num - 1]); i <= 16; i++) {
h[num] -= i * a;
h[num - 1] -= i * b;
h[num + 1] -= i * b;
path[num] = i;
dfs(num + 1, cnt + i);
h[num] += i * a;
h[num - 1] += i * b;
h[num + 1] += i * b;
path[num] = -1;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = (1); i <= (n); i++) {
scanf("%d", &h[i]);
h[i]++;
}
int cnta = 0, cntb = 0;
while (h[1] > 0) {
h[2] -= a;
h[3] -= b;
h[1] -= b;
cnta++;
}
while (h[n] > 0) {
h[n - 1] -= a;
h[n] -= b;
h[n - 2] -= b;
cntb++;
}
memset(path, -1, sizeof(path));
ans = INF;
for (int i = (2); i <= (n - 1); i++) {
if (h[i] > 0) {
dfs(i, 0);
break;
}
}
if (ans == INF)
printf("%d\n", cnta + cntb);
else
printf("%d\n", cnta + cntb + ans);
for (int i = 0; i < cnta; i++) printf("%d ", 2);
for (int i = 0; i < cntb; i++) printf("%d ", n - 1);
if (ans != INF)
for (int i = 1; i <= n; i++)
if (temp[i] != -1) {
for (int j = 0; j < temp[i]; j++) printf("%d ", i);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 12;
const int H = 17;
int n, a, b;
int h[N];
int d[N][H][H];
int p[N][H][H];
void solve() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
memset(d, 0x7f, sizeof d);
for (int i = 0; i < H; i++)
if (b * i > h[1]) d[2][i][0] = i;
for (int i = 3; i < n; i++)
for (int j = 0; j < H; j++)
for (int k = 0; k < H; k++)
for (int l = 0; l < H; l++)
if (a * k + b * (j + l) > h[i - 1]) {
if (d[i][j][k] > d[i - 1][k][l] + j) {
d[i][j][k] = d[i - 1][k][l] + j;
p[i][j][k] = l;
}
}
int ans = INT_MAX;
int J, K;
for (int j = 0; j < H; j++)
for (int k = 0; k < H; k++)
if (b * j > h[n]) {
if (ans > d[n - 1][j][k]) {
ans = d[n - 1][j][k];
J = j;
K = k;
}
}
printf("%d\n", ans);
int c = n - 1;
while (c > 1) {
for (int i = 0; i < J; i++) printf("%d ", c);
int pj = K;
int pk = p[c][J][K];
J = pj, K = pk;
c--;
}
}
int main(void) { solve(); }
|
### Prompt
Generate a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 12;
const int H = 17;
int n, a, b;
int h[N];
int d[N][H][H];
int p[N][H][H];
void solve() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
memset(d, 0x7f, sizeof d);
for (int i = 0; i < H; i++)
if (b * i > h[1]) d[2][i][0] = i;
for (int i = 3; i < n; i++)
for (int j = 0; j < H; j++)
for (int k = 0; k < H; k++)
for (int l = 0; l < H; l++)
if (a * k + b * (j + l) > h[i - 1]) {
if (d[i][j][k] > d[i - 1][k][l] + j) {
d[i][j][k] = d[i - 1][k][l] + j;
p[i][j][k] = l;
}
}
int ans = INT_MAX;
int J, K;
for (int j = 0; j < H; j++)
for (int k = 0; k < H; k++)
if (b * j > h[n]) {
if (ans > d[n - 1][j][k]) {
ans = d[n - 1][j][k];
J = j;
K = k;
}
}
printf("%d\n", ans);
int c = n - 1;
while (c > 1) {
for (int i = 0; i < J; i++) printf("%d ", c);
int pj = K;
int pk = p[c][J][K];
J = pj, K = pk;
c--;
}
}
int main(void) { solve(); }
```
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
int cur[MAX_N], d[MAX_N], c[MAX_N], ans[MAX_N];
int a, b, minn = 1e9;
vector<int> v;
void gen(int k, int n, int sum) {
if (k == n) {
bool ok = 1;
for (int i = (1); (i) < (n + 1); ++i)
if (c[i] > 0) ok = 0;
if (ok && sum < minn) {
minn = sum;
for (int i = 0; (i) < (n); ++i) ans[i] = d[i];
}
return;
}
for (int i = 0; (i) < (9); ++i) {
d[k] = i;
c[k] -= b * i, c[k + 1] -= a * i, c[k + 2] -= b * i;
gen(k + 1, n, sum + i);
c[k] += b * i, c[k + 1] += a * i, c[k + 2] += b * i;
}
}
int main() {
int n;
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; (i) < (n); ++i) scanf("%d", &c[i]), c[i]++;
int k = (c[0] + b - 1) / b;
c[0] -= b * k, c[1] -= a * k, c[2] -= b * k;
for (int i = 0; (i) < (k); ++i) v.push_back(1);
k = 0;
if (c[n - 1] > 0) k = (c[n - 1] + b - 1) / b;
for (int i = 0; (i) < (k); ++i) v.push_back(n - 2);
c[n - 3] -= b * k, c[n - 2] -= a * k, c[n - 1] -= b * k;
gen(0, n - 2, 0);
for (int i = 0; (i) < (n - 2); ++i)
for (int j = 0; (j) < (ans[i]); ++j) v.push_back(i + 1);
printf("%d\n", (int)((v).size()));
for (int k : v) printf("%d ", k + 1);
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
int cur[MAX_N], d[MAX_N], c[MAX_N], ans[MAX_N];
int a, b, minn = 1e9;
vector<int> v;
void gen(int k, int n, int sum) {
if (k == n) {
bool ok = 1;
for (int i = (1); (i) < (n + 1); ++i)
if (c[i] > 0) ok = 0;
if (ok && sum < minn) {
minn = sum;
for (int i = 0; (i) < (n); ++i) ans[i] = d[i];
}
return;
}
for (int i = 0; (i) < (9); ++i) {
d[k] = i;
c[k] -= b * i, c[k + 1] -= a * i, c[k + 2] -= b * i;
gen(k + 1, n, sum + i);
c[k] += b * i, c[k + 1] += a * i, c[k + 2] += b * i;
}
}
int main() {
int n;
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; (i) < (n); ++i) scanf("%d", &c[i]), c[i]++;
int k = (c[0] + b - 1) / b;
c[0] -= b * k, c[1] -= a * k, c[2] -= b * k;
for (int i = 0; (i) < (k); ++i) v.push_back(1);
k = 0;
if (c[n - 1] > 0) k = (c[n - 1] + b - 1) / b;
for (int i = 0; (i) < (k); ++i) v.push_back(n - 2);
c[n - 3] -= b * k, c[n - 2] -= a * k, c[n - 1] -= b * k;
gen(0, n - 2, 0);
for (int i = 0; (i) < (n - 2); ++i)
for (int j = 0; (j) < (ans[i]); ++j) v.push_back(i + 1);
printf("%d\n", (int)((v).size()));
for (int k : v) printf("%d ", k + 1);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int f[20][20][20], p[20][20][20], q[20][20][20];
int n, a, b, h[20];
void print(int now, int x, int y) {
if (now == 2) return;
print(now - 1, p[now][x][y], q[now][x][y]);
for (int i = 0; i < f[now][x][y] - f[now - 1][p[now][x][y]][q[now][x][y]];
i++)
printf("%d ", now - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 16; j++)
for (int k = 0; k <= 16; k++) f[i][j][k] = 0x3f3f3f3f;
f[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++)
for (int j = 0; j <= h[i - 1]; j++)
for (int k = 0; k <= h[i]; k++) {
if (f[i][j][k] == 0x3f3f3f3f) continue;
int mins = (b + j - 1) / b,
maxs = max(mins, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = mins; hit <= maxs; hit++)
if (f[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] >
f[i][j][k] + hit) {
f[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] =
f[i][j][k] + hit;
p[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = j;
q[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = k;
}
}
printf("%d\n", f[n][0][0]);
print(n, 0, 0);
}
|
### Prompt
In Cpp, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int f[20][20][20], p[20][20][20], q[20][20][20];
int n, a, b, h[20];
void print(int now, int x, int y) {
if (now == 2) return;
print(now - 1, p[now][x][y], q[now][x][y]);
for (int i = 0; i < f[now][x][y] - f[now - 1][p[now][x][y]][q[now][x][y]];
i++)
printf("%d ", now - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 16; j++)
for (int k = 0; k <= 16; k++) f[i][j][k] = 0x3f3f3f3f;
f[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++)
for (int j = 0; j <= h[i - 1]; j++)
for (int k = 0; k <= h[i]; k++) {
if (f[i][j][k] == 0x3f3f3f3f) continue;
int mins = (b + j - 1) / b,
maxs = max(mins, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = mins; hit <= maxs; hit++)
if (f[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] >
f[i][j][k] + hit) {
f[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] =
f[i][j][k] + hit;
p[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = j;
q[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = k;
}
}
printf("%d\n", f[n][0][0]);
print(n, 0, 0);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int ans = 1e9, h[15], n, a, b;
vector<int> T, T2;
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[x] < 0) {
T2 = T;
ans = times;
}
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) T.push_back(x);
dfs(x + 1, times + i);
for (int j = 0; j < i; j++) T.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < T2.size(); i++) cout << T2[i] << " ";
cout << endl;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int ans = 1e9, h[15], n, a, b;
vector<int> T, T2;
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[x] < 0) {
T2 = T;
ans = times;
}
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) T.push_back(x);
dfs(x + 1, times + i);
for (int j = 0; j < i; j++) T.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < T2.size(); i++) cout << T2[i] << " ";
cout << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int N, a, b, h[16];
int ret, lg[16], rlg[16];
bool dfs(int id, int sum) {
if (sum >= ret) return false;
if (id == N - 2) {
int lower = (int)ceil((double)(h[N - 1] + 1) / b - EPS);
int rhs2 = h[N - 2] + 1, rhs3 = h[N - 3] + 1;
if (N - 2 >= 1) {
rhs2 -= b * lg[N - 3];
rhs3 -= a * lg[N - 3];
}
if (N - 2 >= 2) {
rhs3 -= b * lg[N - 4];
}
lower = max(lower, (int)ceil((double)rhs2 / a - EPS));
lower = max(lower, (int)ceil((double)rhs3 / b - EPS));
lg[N - 2] = lower;
sum += lower;
if (ret > sum) {
ret = sum;
memcpy(rlg, lg, sizeof(lg));
}
return true;
}
int rhs = h[id - 1] + 1;
if (id >= 2) rhs -= a * lg[id - 1];
if (id >= 3) rhs -= b * lg[id - 2];
int lower = max(0, (int)ceil((double)rhs / b - EPS));
for (int j = lower;; ++j) {
lg[id] = j;
if (!dfs(id + 1, sum + j)) break;
}
return true;
}
int main() {
scanf("%d%d%d", &N, &a, &b);
for (int j = 0; j < (int)(N); ++j) scanf("%d", &h[j]);
ret = 9999999;
dfs(1, 0);
printf("%d\n", ret);
for (int j = (1); j <= (int)(N - 2); ++j)
for (int k = 0; k < (int)(rlg[j]); ++k) printf("%d ", j + 1);
puts("");
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int N, a, b, h[16];
int ret, lg[16], rlg[16];
bool dfs(int id, int sum) {
if (sum >= ret) return false;
if (id == N - 2) {
int lower = (int)ceil((double)(h[N - 1] + 1) / b - EPS);
int rhs2 = h[N - 2] + 1, rhs3 = h[N - 3] + 1;
if (N - 2 >= 1) {
rhs2 -= b * lg[N - 3];
rhs3 -= a * lg[N - 3];
}
if (N - 2 >= 2) {
rhs3 -= b * lg[N - 4];
}
lower = max(lower, (int)ceil((double)rhs2 / a - EPS));
lower = max(lower, (int)ceil((double)rhs3 / b - EPS));
lg[N - 2] = lower;
sum += lower;
if (ret > sum) {
ret = sum;
memcpy(rlg, lg, sizeof(lg));
}
return true;
}
int rhs = h[id - 1] + 1;
if (id >= 2) rhs -= a * lg[id - 1];
if (id >= 3) rhs -= b * lg[id - 2];
int lower = max(0, (int)ceil((double)rhs / b - EPS));
for (int j = lower;; ++j) {
lg[id] = j;
if (!dfs(id + 1, sum + j)) break;
}
return true;
}
int main() {
scanf("%d%d%d", &N, &a, &b);
for (int j = 0; j < (int)(N); ++j) scanf("%d", &h[j]);
ret = 9999999;
dfs(1, 0);
printf("%d\n", ret);
for (int j = (1); j <= (int)(N - 2); ++j)
for (int k = 0; k < (int)(rlg[j]); ++k) printf("%d ", j + 1);
puts("");
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
double DIS(T va, T vb) {
return sqrt((double)(va.x - vb.x) * (va.x - vb.x) +
(va.y - vb.y) * (va.y - vb.y));
}
template <class T>
inline T INT_LEN(T v) {
int len = 1;
while (v /= 10) ++len;
return len;
}
int h[20], hit[20], flec[20];
int N, a, b, flag;
void init(int n, int a, int b) {
memset(hit, 0, sizeof(hit));
memset(flec, 0, sizeof(flec));
while (h[1] >= 0) {
h[1] -= b;
h[2] -= a;
h[3] -= b;
hit[2]++, hit[1]++;
}
while (h[n] >= 0) {
h[n] -= b;
h[~-n] -= a;
h[n - 2] -= b;
hit[~-n]++, hit[n]++;
}
}
void input(int n, int a, int b) {
int i;
for (i = 1; i <= n; i++) scanf("%d", &h[i]);
init(n, a, b);
}
void dfs(int s, int k, int n) {
int i;
if (flag) return;
if (s == ~-n) {
flec[s] = k;
for (i = 2; i <= s; i++) {
if (h[i] >= (flec[~-i] + flec[-~i]) * b + flec[i] * a) break;
}
if (i > s) {
flag = 1;
}
return;
}
for (i = 0; i <= k && !flag; i++) {
flec[s] = i;
dfs(-~s, k - i, n);
}
}
void solve(int n, int a, int b) {
int i;
flag = 0;
for (i = 0; !flag; i++) {
dfs(2, i, n);
if (flag) {
printf("%d\n", i + hit[1] + hit[n]);
for (i = 2; i <= n - 1; i++) {
hit[i] += flec[i];
while (hit[i]--) {
printf("%d ", i);
}
}
puts("");
}
}
}
int main(void) {
while (3 == scanf("%d%d%d", &N, &a, &b)) {
input(N, a, b);
solve(N, a, b);
}
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
double DIS(T va, T vb) {
return sqrt((double)(va.x - vb.x) * (va.x - vb.x) +
(va.y - vb.y) * (va.y - vb.y));
}
template <class T>
inline T INT_LEN(T v) {
int len = 1;
while (v /= 10) ++len;
return len;
}
int h[20], hit[20], flec[20];
int N, a, b, flag;
void init(int n, int a, int b) {
memset(hit, 0, sizeof(hit));
memset(flec, 0, sizeof(flec));
while (h[1] >= 0) {
h[1] -= b;
h[2] -= a;
h[3] -= b;
hit[2]++, hit[1]++;
}
while (h[n] >= 0) {
h[n] -= b;
h[~-n] -= a;
h[n - 2] -= b;
hit[~-n]++, hit[n]++;
}
}
void input(int n, int a, int b) {
int i;
for (i = 1; i <= n; i++) scanf("%d", &h[i]);
init(n, a, b);
}
void dfs(int s, int k, int n) {
int i;
if (flag) return;
if (s == ~-n) {
flec[s] = k;
for (i = 2; i <= s; i++) {
if (h[i] >= (flec[~-i] + flec[-~i]) * b + flec[i] * a) break;
}
if (i > s) {
flag = 1;
}
return;
}
for (i = 0; i <= k && !flag; i++) {
flec[s] = i;
dfs(-~s, k - i, n);
}
}
void solve(int n, int a, int b) {
int i;
flag = 0;
for (i = 0; !flag; i++) {
dfs(2, i, n);
if (flag) {
printf("%d\n", i + hit[1] + hit[n]);
for (i = 2; i <= n - 1; i++) {
hit[i] += flec[i];
while (hit[i]--) {
printf("%d ", i);
}
}
puts("");
}
}
}
int main(void) {
while (3 == scanf("%d%d%d", &N, &a, &b)) {
input(N, a, b);
solve(N, a, b);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int toi(string a) {
int ans;
sscanf(a.c_str(), "%d", &ans);
return ans;
}
string tos(int a) {
ostringstream st;
st << a;
string ans = st.str();
return ans;
}
int a, b, num[15], n;
void g(int &prev, int ¤t, int &next) {
current = max(0, current - a);
prev = max(0, prev - b);
next = max(0, next - b);
}
int dp[15][20][20][20];
int solve(int id, int prev, int current, int next) {
int a = prev, b = current, c = next;
if (id == n - 1) {
if (prev > 0) return dp[id][a][b][c] = 1000000000;
int ret = 0;
while (current > 0) {
g(prev, prev, current);
ret++;
}
return dp[id][a][b][c] = ret;
}
int step = 0;
while (prev > 0) {
g(prev, current, next);
step++;
}
int &ans = dp[id][a][b][c];
if (ans != -1) return ans;
ans = step + solve(id + 1, current, next, num[id + 2]);
while (current > 0) {
g(prev, current, next);
step++;
ans = min(ans, step + solve(id + 1, current, next, num[id + 2]));
}
return ans;
}
void sol(int id, int prev, int current, int next, int ans) {
if (id == n - 1) {
int ret = 0;
while (current > 0) {
g(prev, prev, current);
ret++;
}
for (int i = (0); i < (ret); i++) cout << n - 1 << " ";
return;
}
int step = 0;
while (prev > 0) {
g(prev, current, next);
step++;
}
if (ans - step == dp[id + 1][current][next][num[id + 2]]) {
for (int i = (0); i < (step); i++) cout << id + 1 << " ";
sol(id + 1, current, next, num[id + 2], ans - step);
return;
}
while (current > 0) {
g(prev, current, next);
step++;
if (ans - step == dp[id + 1][current][next][num[id + 2]]) {
for (int i = (0); i < (step); i++) cout << id + 1 << " ";
sol(id + 1, current, next, num[id + 2], ans - step);
return;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = (0); i < (n); i++) {
scanf("%d", &num[i]);
num[i]++;
}
memset(dp, -1, sizeof dp);
int ans = solve(1, num[0], num[1], num[2]);
cout << ans << endl;
sol(1, num[0], num[1], num[2], ans);
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int toi(string a) {
int ans;
sscanf(a.c_str(), "%d", &ans);
return ans;
}
string tos(int a) {
ostringstream st;
st << a;
string ans = st.str();
return ans;
}
int a, b, num[15], n;
void g(int &prev, int ¤t, int &next) {
current = max(0, current - a);
prev = max(0, prev - b);
next = max(0, next - b);
}
int dp[15][20][20][20];
int solve(int id, int prev, int current, int next) {
int a = prev, b = current, c = next;
if (id == n - 1) {
if (prev > 0) return dp[id][a][b][c] = 1000000000;
int ret = 0;
while (current > 0) {
g(prev, prev, current);
ret++;
}
return dp[id][a][b][c] = ret;
}
int step = 0;
while (prev > 0) {
g(prev, current, next);
step++;
}
int &ans = dp[id][a][b][c];
if (ans != -1) return ans;
ans = step + solve(id + 1, current, next, num[id + 2]);
while (current > 0) {
g(prev, current, next);
step++;
ans = min(ans, step + solve(id + 1, current, next, num[id + 2]));
}
return ans;
}
void sol(int id, int prev, int current, int next, int ans) {
if (id == n - 1) {
int ret = 0;
while (current > 0) {
g(prev, prev, current);
ret++;
}
for (int i = (0); i < (ret); i++) cout << n - 1 << " ";
return;
}
int step = 0;
while (prev > 0) {
g(prev, current, next);
step++;
}
if (ans - step == dp[id + 1][current][next][num[id + 2]]) {
for (int i = (0); i < (step); i++) cout << id + 1 << " ";
sol(id + 1, current, next, num[id + 2], ans - step);
return;
}
while (current > 0) {
g(prev, current, next);
step++;
if (ans - step == dp[id + 1][current][next][num[id + 2]]) {
for (int i = (0); i < (step); i++) cout << id + 1 << " ";
sol(id + 1, current, next, num[id + 2], ans - step);
return;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = (0); i < (n); i++) {
scanf("%d", &num[i]);
num[i]++;
}
memset(dp, -1, sizeof dp);
int ans = solve(1, num[0], num[1], num[2]);
cout << ans << endl;
sol(1, num[0], num[1], num[2], ans);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
map<long long, pair<vector<int>, int> > cache;
pair<vector<int>, int> solve(long long h, int n, long long a, long long b) {
if (cache.count(h) > 0) return cache[h];
if (h == 0) {
cache[h] = make_pair(vector<int>(n, 0), 0);
return cache[h];
}
pair<vector<int>, int> best;
best.second = 1000000;
for (int k = 1; k < n - 1; k++) {
int i = k - 1 == 0 ? n - 2 : k - 1;
long long t = h;
long long c = min(a, (t >> (i * 5)) % 0x20);
long long l = min(b, (t >> ((i - 1) * 5)) % 0x20);
long long r = min(b, (t >> ((i + 1) * 5)) % 0x20);
if (c || l || r) {
t -= (c << (i * 5)) + (l << ((i - 1) * 5)) + (r << ((i + 1) * 5));
pair<vector<int>, int> x = solve(t, n, a, b);
if (x.second + 1 < best.second) {
best.first = x.first;
best.first[i]++;
best.second = x.second + 1;
}
}
}
cache[h] = best;
return best;
}
int main(int argc, char *argv[]) {
int n, a, b, x, m = 0, n1 = 0, n2 = 0;
vector<int> h;
cin >> n >> a >> b;
h.resize(n);
for (int i = 0; i < n; i++) cin >> h[i];
vector<int> ans(n, 0);
while (h[0] >= 0) {
h[0] -= min(b, h[0] + 1);
h[1] -= min(a, h[1] + 1);
h[2] -= min(b, h[2] + 1);
ans[1]++;
m++;
}
while (h[n - 1] >= 0) {
h[n - 1] -= min(b, h[n - 1] + 1);
h[n - 2] -= min(a, h[n - 2] + 1);
h[n - 3] -= min(b, h[n - 3] + 1);
ans[n - 2]++;
m++;
}
long long t = 0;
for (int i = 0; i < n; i++) t = (t << 5) + h[n - i - 1] + 1;
pair<vector<int>, int> r = solve(t, n, a, b);
cout << r.second + m << endl;
for (int i = 0; i < r.first.size(); i++) ans[i] += r.first[i];
for (int i = 0; i < ans.size(); i++)
for (int j = 0; j < ans[i]; j++) cout << i + 1 << " ";
cout << endl;
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<long long, pair<vector<int>, int> > cache;
pair<vector<int>, int> solve(long long h, int n, long long a, long long b) {
if (cache.count(h) > 0) return cache[h];
if (h == 0) {
cache[h] = make_pair(vector<int>(n, 0), 0);
return cache[h];
}
pair<vector<int>, int> best;
best.second = 1000000;
for (int k = 1; k < n - 1; k++) {
int i = k - 1 == 0 ? n - 2 : k - 1;
long long t = h;
long long c = min(a, (t >> (i * 5)) % 0x20);
long long l = min(b, (t >> ((i - 1) * 5)) % 0x20);
long long r = min(b, (t >> ((i + 1) * 5)) % 0x20);
if (c || l || r) {
t -= (c << (i * 5)) + (l << ((i - 1) * 5)) + (r << ((i + 1) * 5));
pair<vector<int>, int> x = solve(t, n, a, b);
if (x.second + 1 < best.second) {
best.first = x.first;
best.first[i]++;
best.second = x.second + 1;
}
}
}
cache[h] = best;
return best;
}
int main(int argc, char *argv[]) {
int n, a, b, x, m = 0, n1 = 0, n2 = 0;
vector<int> h;
cin >> n >> a >> b;
h.resize(n);
for (int i = 0; i < n; i++) cin >> h[i];
vector<int> ans(n, 0);
while (h[0] >= 0) {
h[0] -= min(b, h[0] + 1);
h[1] -= min(a, h[1] + 1);
h[2] -= min(b, h[2] + 1);
ans[1]++;
m++;
}
while (h[n - 1] >= 0) {
h[n - 1] -= min(b, h[n - 1] + 1);
h[n - 2] -= min(a, h[n - 2] + 1);
h[n - 3] -= min(b, h[n - 3] + 1);
ans[n - 2]++;
m++;
}
long long t = 0;
for (int i = 0; i < n; i++) t = (t << 5) + h[n - i - 1] + 1;
pair<vector<int>, int> r = solve(t, n, a, b);
cout << r.second + m << endl;
for (int i = 0; i < r.first.size(); i++) ans[i] += r.first[i];
for (int i = 0; i < ans.size(); i++)
for (int j = 0; j < ans[i]; j++) cout << i + 1 << " ";
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
int n, a, b, h[N], dp[11][17][17], sol[11][17][17];
int calc(int i, int pre, int cur) {
if (i == n - 1) return (pre >= h[i - 1] && cur >= h[i]) ? 0 : 1e9;
int &r = dp[i][pre][cur];
if (r != -1) return r;
r = 1e9;
for (int j = 0; j <= 16; j++)
if (pre + j * b >= h[i - 1]) {
int r2 = calc(i + 1, min(16, cur + j * a), min(16, j * b)) + j;
if (r2 < r) {
r = r2;
sol[i][pre][cur] = j;
}
}
return r;
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", h + i);
h[i]++;
}
memset(dp, -1, sizeof dp);
printf("%d\n", calc(1, 0, 0));
for (int i = 1, pre = 0, cur = 0; i < n - 1; i++) {
int j = sol[i][pre][cur];
while (sol[i][pre][cur]--) printf("%d ", i + 1);
pre = min(16, cur + j * a);
cur = min(16, j * b);
}
puts("");
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
int n, a, b, h[N], dp[11][17][17], sol[11][17][17];
int calc(int i, int pre, int cur) {
if (i == n - 1) return (pre >= h[i - 1] && cur >= h[i]) ? 0 : 1e9;
int &r = dp[i][pre][cur];
if (r != -1) return r;
r = 1e9;
for (int j = 0; j <= 16; j++)
if (pre + j * b >= h[i - 1]) {
int r2 = calc(i + 1, min(16, cur + j * a), min(16, j * b)) + j;
if (r2 < r) {
r = r2;
sol[i][pre][cur] = j;
}
}
return r;
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", h + i);
h[i]++;
}
memset(dp, -1, sizeof dp);
printf("%d\n", calc(1, 0, 0));
for (int i = 1, pre = 0, cur = 0; i < n - 1; i++) {
int j = sol[i][pre][cur];
while (sol[i][pre][cur]--) printf("%d ", i + 1);
pre = min(16, cur + j * a);
cur = min(16, j * b);
}
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100;
int a[maxN], A, B, ans[maxN], b[maxN];
int answer = 1000000000, n;
vector<int> answerIndex;
int get() {
int qq = 0;
for (int i = 1; i <= n; ++i) b[i] = a[i];
for (int i = 1; i <= n - 2; ++i) {
if (b[i] < 0) continue;
int cur = b[i] / B + 1;
b[i] -= cur * B, b[i + 1] -= cur * B;
b[i + 2] -= cur * B;
qq += cur;
}
return qq;
}
int counter = 0;
void dfs(int index, int q) {
counter += 1;
if (counter > 1000000) return;
if (q > answer) return;
if (q + get() > answer) return;
if (index == n) {
bool ok = true;
for (int i = 1; i <= n; ++i) {
if (a[i] >= 0) ok = false;
}
if (!ok) return;
if (q == answer) return;
answer = q;
answerIndex.clear();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= ans[i]; ++j) answerIndex.push_back(i);
}
return;
}
if (index >= 3 && a[index - 2] > 0) return;
int maxValue = max(a[index - 1] / B + 1, a[index + 1] / B + 1);
maxValue = max(maxValue, a[index] / A + 1);
maxValue += 1;
for (int val = maxValue; val >= max((int)0, a[index - 1] / B); --val) {
ans[index] += val;
a[index - 1] -= val * B;
a[index + 1] -= val * B;
a[index] -= val * A;
dfs(index + 1, q + val);
ans[index] -= val;
a[index - 1] += val * B;
a[index + 1] += val * B;
a[index] += val * A;
}
}
void dfs2(int index, int q) {
if (q > answer) return;
if (q + get() > answer) return;
if (index == n) {
bool ok = true;
for (int i = 1; i <= n; ++i) {
if (a[i] >= 0) ok = false;
}
if (!ok) return;
if (q == answer) return;
answer = q;
answerIndex.clear();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= ans[i]; ++j) answerIndex.push_back(i);
}
return;
}
if (index >= 3 && a[index - 2] > 0) return;
if (a[index - 1] < 0 && a[index - 2] < 0) {
dfs2(index + 1, q);
return;
}
int maxValue = max(a[index - 1] / B + 1, a[index + 1] / B + 1);
maxValue = max(maxValue, a[index] / A + 1);
maxValue += 1;
for (int val = maxValue; val >= max((int)0, a[index - 1] / B); --val) {
ans[index] += val;
a[index - 1] -= val * B;
a[index + 1] -= val * B;
a[index] -= val * A;
dfs2(index + 1, q + val);
ans[index] -= val;
a[index - 1] += val * B;
a[index + 1] += val * B;
a[index] += val * A;
}
}
void dfs3(int index, int q) {
if (q > answer) return;
if (index == n) {
bool ok = true;
for (int i = 1; i <= n; ++i) {
if (a[i] >= 0) ok = false;
}
if (!ok) return;
if (q == answer) return;
answer = q;
answerIndex.clear();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= ans[i]; ++j) answerIndex.push_back(i);
}
return;
}
if (index >= 3 && a[index - 2] > 0) return;
int maxValue = max(a[index - 1] / B + 1, a[index + 1] / B + 1);
maxValue = max(maxValue, a[index] / A + 1);
maxValue += 1;
for (int val = maxValue; val >= 0; --val) {
ans[index] += val;
a[index - 1] -= val * B;
a[index + 1] -= val * B;
a[index] -= val * A;
dfs3(index + 1, q + val);
ans[index] -= val;
a[index - 1] += val * B;
a[index + 1] += val * B;
a[index] += val * A;
}
}
int main() {
cin >> n >> A >> B;
for (int i = 1; i <= n; ++i) cin >> a[i];
dfs(2, 0);
dfs2(2, 0);
if (n <= 10) {
counter = 0;
dfs3(2, 0);
}
cout << answerIndex.size() << endl;
for (int i = 0; i < answerIndex.size(); ++i) cout << answerIndex[i] << " ";
cout << endl;
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100;
int a[maxN], A, B, ans[maxN], b[maxN];
int answer = 1000000000, n;
vector<int> answerIndex;
int get() {
int qq = 0;
for (int i = 1; i <= n; ++i) b[i] = a[i];
for (int i = 1; i <= n - 2; ++i) {
if (b[i] < 0) continue;
int cur = b[i] / B + 1;
b[i] -= cur * B, b[i + 1] -= cur * B;
b[i + 2] -= cur * B;
qq += cur;
}
return qq;
}
int counter = 0;
void dfs(int index, int q) {
counter += 1;
if (counter > 1000000) return;
if (q > answer) return;
if (q + get() > answer) return;
if (index == n) {
bool ok = true;
for (int i = 1; i <= n; ++i) {
if (a[i] >= 0) ok = false;
}
if (!ok) return;
if (q == answer) return;
answer = q;
answerIndex.clear();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= ans[i]; ++j) answerIndex.push_back(i);
}
return;
}
if (index >= 3 && a[index - 2] > 0) return;
int maxValue = max(a[index - 1] / B + 1, a[index + 1] / B + 1);
maxValue = max(maxValue, a[index] / A + 1);
maxValue += 1;
for (int val = maxValue; val >= max((int)0, a[index - 1] / B); --val) {
ans[index] += val;
a[index - 1] -= val * B;
a[index + 1] -= val * B;
a[index] -= val * A;
dfs(index + 1, q + val);
ans[index] -= val;
a[index - 1] += val * B;
a[index + 1] += val * B;
a[index] += val * A;
}
}
void dfs2(int index, int q) {
if (q > answer) return;
if (q + get() > answer) return;
if (index == n) {
bool ok = true;
for (int i = 1; i <= n; ++i) {
if (a[i] >= 0) ok = false;
}
if (!ok) return;
if (q == answer) return;
answer = q;
answerIndex.clear();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= ans[i]; ++j) answerIndex.push_back(i);
}
return;
}
if (index >= 3 && a[index - 2] > 0) return;
if (a[index - 1] < 0 && a[index - 2] < 0) {
dfs2(index + 1, q);
return;
}
int maxValue = max(a[index - 1] / B + 1, a[index + 1] / B + 1);
maxValue = max(maxValue, a[index] / A + 1);
maxValue += 1;
for (int val = maxValue; val >= max((int)0, a[index - 1] / B); --val) {
ans[index] += val;
a[index - 1] -= val * B;
a[index + 1] -= val * B;
a[index] -= val * A;
dfs2(index + 1, q + val);
ans[index] -= val;
a[index - 1] += val * B;
a[index + 1] += val * B;
a[index] += val * A;
}
}
void dfs3(int index, int q) {
if (q > answer) return;
if (index == n) {
bool ok = true;
for (int i = 1; i <= n; ++i) {
if (a[i] >= 0) ok = false;
}
if (!ok) return;
if (q == answer) return;
answer = q;
answerIndex.clear();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= ans[i]; ++j) answerIndex.push_back(i);
}
return;
}
if (index >= 3 && a[index - 2] > 0) return;
int maxValue = max(a[index - 1] / B + 1, a[index + 1] / B + 1);
maxValue = max(maxValue, a[index] / A + 1);
maxValue += 1;
for (int val = maxValue; val >= 0; --val) {
ans[index] += val;
a[index - 1] -= val * B;
a[index + 1] -= val * B;
a[index] -= val * A;
dfs3(index + 1, q + val);
ans[index] -= val;
a[index - 1] += val * B;
a[index + 1] += val * B;
a[index] += val * A;
}
}
int main() {
cin >> n >> A >> B;
for (int i = 1; i <= n; ++i) cin >> a[i];
dfs(2, 0);
dfs2(2, 0);
if (n <= 10) {
counter = 0;
dfs3(2, 0);
}
cout << answerIndex.size() << endl;
for (int i = 0; i < answerIndex.size(); ++i) cout << answerIndex[i] << " ";
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline string tostring(T a) {
ostringstream os("");
os << a;
return os.str();
}
template <typename T>
inline vector<string> parse(T str) {
vector<string> res;
string s;
istringstream os(str);
while (os >> s) res.push_back(s);
return res;
}
template <typename T>
inline long long toLong(T a) {
long long res;
istringstream os(a);
os >> res;
return res;
}
template <typename T>
inline int toInt(T a) {
int res;
istringstream os(a);
os >> res;
return res;
}
int arr[20];
int dp[12][500][500];
int n, a, b;
vector<pair<int, int> > save;
int solve(int pos, int last, int cur) {
if (pos == n) {
if (last > arr[pos - 1] && cur > arr[pos]) return 0;
return INT_MAX / 3;
}
int &ret = dp[pos][last][cur];
if (ret != -1) return ret;
ret = INT_MAX / 3;
for (int i = 0; i <= 16; i++) {
if (last + i * b > arr[pos - 1]) {
ret = (ret > i + solve(pos + 1, cur + i * a, i * b)
? i + solve(pos + 1, cur + i * a, i * b)
: ret);
}
}
return ret;
}
void print(int pos, int last, int cur) {
if (pos == n) return;
int &ret = dp[pos][last][cur];
for (int i = 0; i <= 16; i++) {
if (last + i * b > arr[pos - 1] &&
ret == i + solve(pos + 1, cur + i * a, i * b)) {
save.push_back(make_pair(pos, i));
print(pos + 1, cur + i * a, i * b);
return;
}
}
}
int main() {
int x, y, i, j, m;
int ks, cas;
cin >> n >> a >> b;
for (i = 1; i <= n; i++) scanf("%d", &arr[i]);
memset(dp, -1, sizeof dp);
int res = solve(2, 0, 0);
print(2, 0, 0);
cout << res << endl;
for (int i = (0); i < (save.size()); i++) {
pair<int, int> p = save[i];
for (int j = (0); j < (p.second); j++) {
printf("%d ", p.first);
}
}
puts("");
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline string tostring(T a) {
ostringstream os("");
os << a;
return os.str();
}
template <typename T>
inline vector<string> parse(T str) {
vector<string> res;
string s;
istringstream os(str);
while (os >> s) res.push_back(s);
return res;
}
template <typename T>
inline long long toLong(T a) {
long long res;
istringstream os(a);
os >> res;
return res;
}
template <typename T>
inline int toInt(T a) {
int res;
istringstream os(a);
os >> res;
return res;
}
int arr[20];
int dp[12][500][500];
int n, a, b;
vector<pair<int, int> > save;
int solve(int pos, int last, int cur) {
if (pos == n) {
if (last > arr[pos - 1] && cur > arr[pos]) return 0;
return INT_MAX / 3;
}
int &ret = dp[pos][last][cur];
if (ret != -1) return ret;
ret = INT_MAX / 3;
for (int i = 0; i <= 16; i++) {
if (last + i * b > arr[pos - 1]) {
ret = (ret > i + solve(pos + 1, cur + i * a, i * b)
? i + solve(pos + 1, cur + i * a, i * b)
: ret);
}
}
return ret;
}
void print(int pos, int last, int cur) {
if (pos == n) return;
int &ret = dp[pos][last][cur];
for (int i = 0; i <= 16; i++) {
if (last + i * b > arr[pos - 1] &&
ret == i + solve(pos + 1, cur + i * a, i * b)) {
save.push_back(make_pair(pos, i));
print(pos + 1, cur + i * a, i * b);
return;
}
}
}
int main() {
int x, y, i, j, m;
int ks, cas;
cin >> n >> a >> b;
for (i = 1; i <= n; i++) scanf("%d", &arr[i]);
memset(dp, -1, sizeof dp);
int res = solve(2, 0, 0);
print(2, 0, 0);
cout << res << endl;
for (int i = (0); i < (save.size()); i++) {
pair<int, int> p = save[i];
for (int j = (0); j < (p.second); j++) {
printf("%d ", p.first);
}
}
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
int n, a, b, nowmax;
queue<pair<vector<int>, vector<int> > > Q;
vector<int> now(15), ansx(15), h(15);
set<vector<int> > S;
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
now[0] = (h[1] + 1) / b + ((h[1] + 1) % b > 0), h[1] -= now[0] * b,
h[3] -= now[0] * b, h[2] -= now[0] * a, now[2] += now[0];
if (h[n] >= 0) {
int tmp = (h[n] + 1) / b + ((h[n] + 1) % b > 0);
now[0] += tmp, h[n] -= tmp * b, h[n - 1] -= tmp * a, h[n - 2] -= tmp * b,
now[n - 1] += tmp;
}
Q.push(make_pair(now, h));
while (!Q.empty()) {
now = Q.front().first, h = Q.front().second, Q.pop();
now[0]++;
if (now[0] < nowmax) nowmax = now[0], S.clear();
for (int i = 2, flag; i < n; ++i) {
if (h[i] < 0 && h[i - 1] < 0 && h[i + 1] < 0) continue;
now[i]++;
h[i] -= a, h[i - 1] -= b, h[i + 1] -= b;
flag = 0;
for (int j = 1; j <= n; j++)
if (h[j] >= 0) {
flag = 1;
break;
}
if (!flag) {
printf("%d\n", now[0]);
for (int i = 2; i < n; ++i)
while (now[i]--) printf("%d ", i);
return 0;
} else if (!S.count(now))
Q.push(make_pair(now, h)), S.insert(now);
now[i]--, h[i] += a, h[i - 1] += b, h[i + 1] += b;
}
}
printf("%d\n", now[0] - 1);
for (int i = 2; i < n; ++i)
while (now[i]--) printf("%d ", i);
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
int n, a, b, nowmax;
queue<pair<vector<int>, vector<int> > > Q;
vector<int> now(15), ansx(15), h(15);
set<vector<int> > S;
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
now[0] = (h[1] + 1) / b + ((h[1] + 1) % b > 0), h[1] -= now[0] * b,
h[3] -= now[0] * b, h[2] -= now[0] * a, now[2] += now[0];
if (h[n] >= 0) {
int tmp = (h[n] + 1) / b + ((h[n] + 1) % b > 0);
now[0] += tmp, h[n] -= tmp * b, h[n - 1] -= tmp * a, h[n - 2] -= tmp * b,
now[n - 1] += tmp;
}
Q.push(make_pair(now, h));
while (!Q.empty()) {
now = Q.front().first, h = Q.front().second, Q.pop();
now[0]++;
if (now[0] < nowmax) nowmax = now[0], S.clear();
for (int i = 2, flag; i < n; ++i) {
if (h[i] < 0 && h[i - 1] < 0 && h[i + 1] < 0) continue;
now[i]++;
h[i] -= a, h[i - 1] -= b, h[i + 1] -= b;
flag = 0;
for (int j = 1; j <= n; j++)
if (h[j] >= 0) {
flag = 1;
break;
}
if (!flag) {
printf("%d\n", now[0]);
for (int i = 2; i < n; ++i)
while (now[i]--) printf("%d ", i);
return 0;
} else if (!S.count(now))
Q.push(make_pair(now, h)), S.insert(now);
now[i]--, h[i] += a, h[i - 1] += b, h[i + 1] += b;
}
}
printf("%d\n", now[0] - 1);
for (int i = 2; i < n; ++i)
while (now[i]--) printf("%d ", i);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, t, arr[11];
int dp[11][17][17];
int dpp[11][17][17];
int solve(int i, int p, int c) {
if (i == n - 1) return (p == 0 && c == 0) ? 0 : 1e6;
int tmp, pp, cc;
int &ret = dp[i][p][c], &j = dpp[i][p][c];
if (ret != -1) return ret;
ret = 1e6;
j = 1e6;
if (p == 0) ret = solve(i + 1, c, arr[i + 1]), j = 0;
for (int k = max(p / b + ((p % b) != 0), 1);; ++k) {
pp = max(0, c - k * a);
cc = max(0, arr[i + 1] - k * b);
tmp = solve(i + 1, pp, cc);
if (tmp + k < ret) {
ret = tmp + k;
j = k;
}
if (arr[i + 1] <= k * b && c <= k * a) break;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 0; i < n; ++arr[i], ++i) cin >> arr[i];
memset(dp, -1, sizeof dp);
t = solve(1, arr[0], arr[1]);
cout << t << endl;
for (int i = 1, p = arr[0], c = arr[1]; i < n - 1; ++i) {
int j = dpp[i][p][c];
p = max(0, c - j * a);
c = max(0, arr[i + 1] - j * b);
while (j--) {
cout << i + 1 << " ";
}
}
}
|
### Prompt
In CPP, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, t, arr[11];
int dp[11][17][17];
int dpp[11][17][17];
int solve(int i, int p, int c) {
if (i == n - 1) return (p == 0 && c == 0) ? 0 : 1e6;
int tmp, pp, cc;
int &ret = dp[i][p][c], &j = dpp[i][p][c];
if (ret != -1) return ret;
ret = 1e6;
j = 1e6;
if (p == 0) ret = solve(i + 1, c, arr[i + 1]), j = 0;
for (int k = max(p / b + ((p % b) != 0), 1);; ++k) {
pp = max(0, c - k * a);
cc = max(0, arr[i + 1] - k * b);
tmp = solve(i + 1, pp, cc);
if (tmp + k < ret) {
ret = tmp + k;
j = k;
}
if (arr[i + 1] <= k * b && c <= k * a) break;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 0; i < n; ++arr[i], ++i) cin >> arr[i];
memset(dp, -1, sizeof dp);
t = solve(1, arr[0], arr[1]);
cout << t << endl;
for (int i = 1, p = arr[0], c = arr[1]; i < n - 1; ++i) {
int j = dpp[i][p][c];
p = max(0, c - j * a);
c = max(0, arr[i + 1] - j * b);
while (j--) {
cout << i + 1 << " ";
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h[10];
int memo[10][17][17], choose[10][17][17];
int solve(int pos, int last1, int last2) {
if (pos == n - 1) {
if (b * last2 > h[pos]) return 0;
return 200;
}
int &ret = memo[pos][last1][last2];
if (ret == -1) {
ret = 200;
for (int i = 0; i <= 16; ++i) {
if (b * i + a * last2 + b * last1 > h[pos - 1]) {
int aux = i + solve(pos + 1, last2, i);
if (aux < ret) {
ret = aux;
choose[pos][last1][last2] = i;
}
}
}
}
return ret;
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 0; i < n; ++i) scanf("%d", &h[i]);
memset(memo, -1, sizeof memo);
printf("%d\n", solve(1, 0, 0));
for (int i = 1, last1 = 0, last2 = 0; i < n - 1; ++i) {
int m = choose[i][last1][last2];
for (int j = 0; j < m; ++j) printf("%d ", i + 1);
last1 = last2;
last2 = m;
}
printf("\n");
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h[10];
int memo[10][17][17], choose[10][17][17];
int solve(int pos, int last1, int last2) {
if (pos == n - 1) {
if (b * last2 > h[pos]) return 0;
return 200;
}
int &ret = memo[pos][last1][last2];
if (ret == -1) {
ret = 200;
for (int i = 0; i <= 16; ++i) {
if (b * i + a * last2 + b * last1 > h[pos - 1]) {
int aux = i + solve(pos + 1, last2, i);
if (aux < ret) {
ret = aux;
choose[pos][last1][last2] = i;
}
}
}
}
return ret;
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 0; i < n; ++i) scanf("%d", &h[i]);
memset(memo, -1, sizeof memo);
printf("%d\n", solve(1, 0, 0));
for (int i = 1, last1 = 0, last2 = 0; i < n - 1; ++i) {
int m = choose[i][last1][last2];
for (int j = 0; j < m; ++j) printf("%d ", i + 1);
last1 = last2;
last2 = m;
}
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getchar();
}
return x * f;
}
int n, a, b, h[15], tot, ans;
int p[155], val[155];
inline void check() {
int yu = max(h[n - 1] / a + (h[n - 1] >= 0), h[n] / b + (h[n] >= 0));
for (int i = 1; i <= yu; i++) p[++tot] = n - 1;
if (ans > tot) {
for (int i = 1; i <= tot; i++) val[i] = p[i];
ans = tot;
}
tot -= yu;
}
inline void dfs(int now) {
if (now > n - 1) {
check();
return;
}
if (h[now - 1] < 0) dfs(now + 1);
int last = tot, A = h[now - 1], B = h[now], C = h[now + 1];
while (1) {
h[now] -= a;
h[now - 1] -= b;
h[now + 1] -= b;
p[++tot] = now;
if (h[now - 1] < 0) dfs(now + 1);
if ((h[now - 1] < 0 && h[now] < 0) || tot >= ans) {
tot = last;
h[now - 1] = A;
h[now] = B;
h[now + 1] = C;
break;
}
}
}
signed main() {
n = read();
a = read();
b = read();
for (int i = 1; i <= n; i++) h[i] = read();
ans = 2147483647;
tot = 0;
dfs(2);
printf("%d\n", ans);
for (int i = 1; i <= ans; i++) printf("%d ", val[i]);
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getchar();
}
return x * f;
}
int n, a, b, h[15], tot, ans;
int p[155], val[155];
inline void check() {
int yu = max(h[n - 1] / a + (h[n - 1] >= 0), h[n] / b + (h[n] >= 0));
for (int i = 1; i <= yu; i++) p[++tot] = n - 1;
if (ans > tot) {
for (int i = 1; i <= tot; i++) val[i] = p[i];
ans = tot;
}
tot -= yu;
}
inline void dfs(int now) {
if (now > n - 1) {
check();
return;
}
if (h[now - 1] < 0) dfs(now + 1);
int last = tot, A = h[now - 1], B = h[now], C = h[now + 1];
while (1) {
h[now] -= a;
h[now - 1] -= b;
h[now + 1] -= b;
p[++tot] = now;
if (h[now - 1] < 0) dfs(now + 1);
if ((h[now - 1] < 0 && h[now] < 0) || tot >= ans) {
tot = last;
h[now - 1] = A;
h[now] = B;
h[now + 1] = C;
break;
}
}
}
signed main() {
n = read();
a = read();
b = read();
for (int i = 1; i <= n; i++) h[i] = read();
ans = 2147483647;
tot = 0;
dfs(2);
printf("%d\n", ans);
for (int i = 1; i <= ans; i++) printf("%d ", val[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
int n, a, b;
int h[20];
int c[20];
int hit[20];
int best[20];
int total_hits;
int best_total_hits;
int mdiv(int delta, int divisor) {
if (delta < 0) {
return 0;
}
if (delta % divisor == 0) {
return delta / divisor;
} else {
return delta / divisor + 1;
}
}
void solve() {
bool miss = false;
for (int i = 0; i < n; i++) {
if (c[i] < h[i]) {
miss = true;
break;
}
}
if (!miss && total_hits < best_total_hits) {
best_total_hits = total_hits;
memcpy(best, hit, sizeof(hit));
}
}
void rec(int index) {
if (total_hits >= best_total_hits) {
return;
}
if (index == n - 1) {
solve();
return;
}
int min_c = mdiv(h[index - 1] - c[index - 1], b);
int max_c = std::max(min_c, mdiv(h[index] - c[index], a));
max_c = std::max(max_c, mdiv(h[index + 1] - c[index + 1], b));
if (index == n - 2) {
min_c = max_c;
}
c[index - 1] += b * (min_c - 1);
c[index] += a * (min_c - 1);
c[index + 1] += b * (min_c - 1);
hit[index] += (min_c - 1);
total_hits += (min_c - 1);
for (int i = min_c; i <= max_c; i++) {
c[index - 1] += b;
c[index] += a;
c[index + 1] += b;
hit[index]++;
total_hits++;
rec(index + 1);
}
c[index - 1] -= b * max_c;
c[index] -= a * max_c;
c[index + 1] -= b * max_c;
hit[index] -= max_c;
total_hits -= max_c;
}
int main() {
memset(c, 0, sizeof(c));
memset(hit, 0, sizeof(hit));
scanf("%d %d %d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
++h[i];
}
total_hits = 0;
best_total_hits = 1000000000;
rec(1);
printf("%d\n", best_total_hits);
for (int i = 0; i < n; i++) {
for (int j = 0; j < best[i]; ++j) {
printf("%d ", i + 1);
}
}
printf("\n");
}
|
### Prompt
Please formulate a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
int n, a, b;
int h[20];
int c[20];
int hit[20];
int best[20];
int total_hits;
int best_total_hits;
int mdiv(int delta, int divisor) {
if (delta < 0) {
return 0;
}
if (delta % divisor == 0) {
return delta / divisor;
} else {
return delta / divisor + 1;
}
}
void solve() {
bool miss = false;
for (int i = 0; i < n; i++) {
if (c[i] < h[i]) {
miss = true;
break;
}
}
if (!miss && total_hits < best_total_hits) {
best_total_hits = total_hits;
memcpy(best, hit, sizeof(hit));
}
}
void rec(int index) {
if (total_hits >= best_total_hits) {
return;
}
if (index == n - 1) {
solve();
return;
}
int min_c = mdiv(h[index - 1] - c[index - 1], b);
int max_c = std::max(min_c, mdiv(h[index] - c[index], a));
max_c = std::max(max_c, mdiv(h[index + 1] - c[index + 1], b));
if (index == n - 2) {
min_c = max_c;
}
c[index - 1] += b * (min_c - 1);
c[index] += a * (min_c - 1);
c[index + 1] += b * (min_c - 1);
hit[index] += (min_c - 1);
total_hits += (min_c - 1);
for (int i = min_c; i <= max_c; i++) {
c[index - 1] += b;
c[index] += a;
c[index + 1] += b;
hit[index]++;
total_hits++;
rec(index + 1);
}
c[index - 1] -= b * max_c;
c[index] -= a * max_c;
c[index + 1] -= b * max_c;
hit[index] -= max_c;
total_hits -= max_c;
}
int main() {
memset(c, 0, sizeof(c));
memset(hit, 0, sizeof(hit));
scanf("%d %d %d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
++h[i];
}
total_hits = 0;
best_total_hits = 1000000000;
rec(1);
printf("%d\n", best_total_hits);
for (int i = 0; i < n; i++) {
for (int j = 0; j < best[i]; ++j) {
printf("%d ", i + 1);
}
}
printf("\n");
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
int h[maxn], n, a, b;
vector<int> G, ans;
void dfs(int ith, bool ok) {
if (ith == n && ok == 0) {
if (G.size() < ans.size()) ans = G;
return;
}
int size = 0;
while (ok && h[ith - 1] >= 0) {
h[ith - 1] -= b;
h[ith] -= a;
h[ith + 1] -= b;
G.push_back(ith);
size++;
}
while (h[ith] >= 0) {
dfs(ith + 1, 1);
h[ith - 1] -= b;
h[ith] -= a;
h[ith + 1] -= b;
G.push_back(ith);
size++;
}
dfs(ith + 1, 0);
h[ith - 1] += size * b;
h[ith] += size * a;
h[ith + 1] += size * b;
while (size--) G.erase(G.end() - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
while (h[1] >= 0) {
h[1] -= b;
h[2] -= a;
h[3] -= b;
G.push_back(2);
}
while (h[n] >= 0) {
h[n - 2] -= b;
h[n - 1] -= a;
h[n] -= b;
G.push_back(n - 1);
}
ans = G;
for (int i = 1; i <= 100; i++) ans.push_back(i);
dfs(2, 0);
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
int h[maxn], n, a, b;
vector<int> G, ans;
void dfs(int ith, bool ok) {
if (ith == n && ok == 0) {
if (G.size() < ans.size()) ans = G;
return;
}
int size = 0;
while (ok && h[ith - 1] >= 0) {
h[ith - 1] -= b;
h[ith] -= a;
h[ith + 1] -= b;
G.push_back(ith);
size++;
}
while (h[ith] >= 0) {
dfs(ith + 1, 1);
h[ith - 1] -= b;
h[ith] -= a;
h[ith + 1] -= b;
G.push_back(ith);
size++;
}
dfs(ith + 1, 0);
h[ith - 1] += size * b;
h[ith] += size * a;
h[ith + 1] += size * b;
while (size--) G.erase(G.end() - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
while (h[1] >= 0) {
h[1] -= b;
h[2] -= a;
h[3] -= b;
G.push_back(2);
}
while (h[n] >= 0) {
h[n - 2] -= b;
h[n - 1] -= a;
h[n] -= b;
G.push_back(n - 1);
}
ans = G;
for (int i = 1; i <= 100; i++) ans.push_back(i);
dfs(2, 0);
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const double PI = acos(-1);
long long gcd() { return 0ll; }
template <typename T, typename... Args>
T gcd(T a, Args... args) {
return __gcd(a, (__typeof(a))gcd(args...));
}
vector<int> ans;
int h[17];
int dp[17][17][17], ht[17][17][17], at[17][17][17];
int n, a, b;
int solve(int i, int j, int k) {
if (i == n - 1) {
return j > 0 ? INT_MAX : 0;
}
int &res = dp[i][j][k];
if (res != -1) return res;
res = INT_MAX;
int x = h[i] - k * b, p;
x = max(0, x);
for (__typeof(17) t = (0) - ((0) > (17)); t != (17) - ((0) > (17));
t += 1 - 2 * ((0) > (17))) {
if ((j - t * b) > 0) continue;
p = solve(i + 1, max(0, x - t * a), t) + t;
if (p < res) {
res = p;
ht[i][j][k] = max(0, x - t * a);
at[i][j][k] = t;
}
}
return res;
}
void path(int i, int j, int k) {
if (i == n - 1) return;
for (__typeof(at[i][j][k]) t = (0) - ((0) > (at[i][j][k]));
t != (at[i][j][k]) - ((0) > (at[i][j][k]));
t += 1 - 2 * ((0) > (at[i][j][k])))
ans.emplace_back(i);
path(i + 1, ht[i][j][k], at[i][j][k]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
{
memset(dp, -1, sizeof(dp));
cin >> n >> a >> b;
for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
i += 1 - 2 * ((0) > (n)))
cin >> h[i], h[i]++;
while (h[0] > 0) {
h[0] -= b;
h[1] -= a;
h[2] -= b;
ans.emplace_back(1);
}
h[0] = max(0, h[0]);
h[1] = max(0, h[1]);
h[2] = max(0, h[2]);
while (h[n - 1] > 0) {
h[n - 1] -= b;
h[n - 2] -= a;
h[n - 3] -= b;
ans.emplace_back(n - 2);
}
h[n - 1] = max(0, h[n - 1]);
h[n - 2] = max(0, h[n - 2]);
h[n - 3] = max(0, h[n - 3]);
solve(1, 0, 0);
path(1, 0, 0);
cout << ans.size() << "\n";
for (auto it : ans) cout << it + 1 << " ";
}
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const double PI = acos(-1);
long long gcd() { return 0ll; }
template <typename T, typename... Args>
T gcd(T a, Args... args) {
return __gcd(a, (__typeof(a))gcd(args...));
}
vector<int> ans;
int h[17];
int dp[17][17][17], ht[17][17][17], at[17][17][17];
int n, a, b;
int solve(int i, int j, int k) {
if (i == n - 1) {
return j > 0 ? INT_MAX : 0;
}
int &res = dp[i][j][k];
if (res != -1) return res;
res = INT_MAX;
int x = h[i] - k * b, p;
x = max(0, x);
for (__typeof(17) t = (0) - ((0) > (17)); t != (17) - ((0) > (17));
t += 1 - 2 * ((0) > (17))) {
if ((j - t * b) > 0) continue;
p = solve(i + 1, max(0, x - t * a), t) + t;
if (p < res) {
res = p;
ht[i][j][k] = max(0, x - t * a);
at[i][j][k] = t;
}
}
return res;
}
void path(int i, int j, int k) {
if (i == n - 1) return;
for (__typeof(at[i][j][k]) t = (0) - ((0) > (at[i][j][k]));
t != (at[i][j][k]) - ((0) > (at[i][j][k]));
t += 1 - 2 * ((0) > (at[i][j][k])))
ans.emplace_back(i);
path(i + 1, ht[i][j][k], at[i][j][k]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
{
memset(dp, -1, sizeof(dp));
cin >> n >> a >> b;
for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
i += 1 - 2 * ((0) > (n)))
cin >> h[i], h[i]++;
while (h[0] > 0) {
h[0] -= b;
h[1] -= a;
h[2] -= b;
ans.emplace_back(1);
}
h[0] = max(0, h[0]);
h[1] = max(0, h[1]);
h[2] = max(0, h[2]);
while (h[n - 1] > 0) {
h[n - 1] -= b;
h[n - 2] -= a;
h[n - 3] -= b;
ans.emplace_back(n - 2);
}
h[n - 1] = max(0, h[n - 1]);
h[n - 2] = max(0, h[n - 2]);
h[n - 3] = max(0, h[n - 3]);
solve(1, 0, 0);
path(1, 0, 0);
cout << ans.size() << "\n";
for (auto it : ans) cout << it + 1 << " ";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long a, b, n, i, ans, h[20] = {}, f[100] = {};
bool dfs(long d, long x) {
if (d == 0) {
for (int i = 1; i <= n; i++)
if (h[i] >= 0) return false;
return true;
}
if (x == n) {
f[d] = n - 1;
h[n] -= b;
if (dfs(d - 1, x)) return true;
h[n] += b;
return false;
}
if (x == 1 || (h[x] < 0 && h[x - 1] < 0))
return dfs(d, x + 1);
else {
if (h[x - 1] < 0 && dfs(d, x + 1)) return true;
h[x - 1] -= b;
h[x] -= a;
h[x + 1] -= b;
f[d] = x;
if (dfs(d - 1, x)) return true;
h[x - 1] += b;
h[x] += a;
h[x + 1] += b;
}
return false;
}
int main() {
cin >> n >> a >> b;
for (i = 1; i <= n; i++) cin >> h[i];
for (ans = 1;; ans++) {
if (dfs(ans, 1)) {
cout << ans << endl;
for (i = ans; i > 1; i--) cout << f[i] << ' ';
cout << f[1] << endl;
return 0;
}
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long a, b, n, i, ans, h[20] = {}, f[100] = {};
bool dfs(long d, long x) {
if (d == 0) {
for (int i = 1; i <= n; i++)
if (h[i] >= 0) return false;
return true;
}
if (x == n) {
f[d] = n - 1;
h[n] -= b;
if (dfs(d - 1, x)) return true;
h[n] += b;
return false;
}
if (x == 1 || (h[x] < 0 && h[x - 1] < 0))
return dfs(d, x + 1);
else {
if (h[x - 1] < 0 && dfs(d, x + 1)) return true;
h[x - 1] -= b;
h[x] -= a;
h[x + 1] -= b;
f[d] = x;
if (dfs(d - 1, x)) return true;
h[x - 1] += b;
h[x] += a;
h[x + 1] += b;
}
return false;
}
int main() {
cin >> n >> a >> b;
for (i = 1; i <= n; i++) cin >> h[i];
for (ans = 1;; ans++) {
if (dfs(ans, 1)) {
cout << ans << endl;
for (i = ans; i > 1; i--) cout << f[i] << ' ';
cout << f[1] << endl;
return 0;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15 + 2;
int n, a, b, h[maxn], ans = 0x7fffffff;
vector<int> hit, tmp;
void health(int c, int a, int b) {
h[c - 1] -= b;
h[c + 1] -= b;
h[c] -= a;
return;
}
void dfs(int c, int times) {
if (times >= ans) return;
if (c == n) {
if (h[n] < 0) {
ans = times;
hit = tmp;
}
return;
}
for (int i = 0;
i <= max(h[c - 1] / b + 1, max(h[c] / a + 1, h[c + 1] / b + 1)); i++) {
if (h[c - 1] - b * i < 0) {
health(c, a * i, b * i);
for (int j = 0; j < i; j++) tmp.push_back(c);
dfs(c + 1, times + i);
health(c, -a * i, -b * i);
for (int j = 0; j < i; j++) tmp.pop_back();
}
}
return;
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", h + i);
}
dfs(2, 0);
printf("%d\n", ans);
for (int i = 0; i < hit.size(); i++) printf("%d ", hit[i]);
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15 + 2;
int n, a, b, h[maxn], ans = 0x7fffffff;
vector<int> hit, tmp;
void health(int c, int a, int b) {
h[c - 1] -= b;
h[c + 1] -= b;
h[c] -= a;
return;
}
void dfs(int c, int times) {
if (times >= ans) return;
if (c == n) {
if (h[n] < 0) {
ans = times;
hit = tmp;
}
return;
}
for (int i = 0;
i <= max(h[c - 1] / b + 1, max(h[c] / a + 1, h[c + 1] / b + 1)); i++) {
if (h[c - 1] - b * i < 0) {
health(c, a * i, b * i);
for (int j = 0; j < i; j++) tmp.push_back(c);
dfs(c + 1, times + i);
health(c, -a * i, -b * i);
for (int j = 0; j < i; j++) tmp.pop_back();
}
}
return;
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", h + i);
}
dfs(2, 0);
printf("%d\n", ans);
for (int i = 0; i < hit.size(); i++) printf("%d ", hit[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long n, a, b;
long long h[20];
long long dp[20][20][20][20];
const long long INF = 1e16;
long long solve(long long id, long long hl, long long hc, long long hr) {
if (id == n) {
if (hc == 0 && hl == 0 && hr == 0) return 0;
return INF;
}
if (dp[id][hl][hc][hr] != -1) return dp[id][hl][hc][hr];
long long ret = 0;
if (hl == 0 && hc == 0 && hr == 0) {
ret = solve(id + 1, hc, hr, h[id + 2]);
} else {
ret = 1 + solve(id, max(0LL, hl - b), max(0LL, hc - a), max(0LL, hr - b));
if (hl == 0) {
ret = min(ret, solve(id + 1, hc, hr, h[id + 2]));
}
}
return dp[id][hl][hc][hr] = ret;
}
void trace(long long id, long long hl, long long hc, long long hr) {
if (id == n) {
return;
}
if (hl == 0 && hc == 0 && hr == 0)
return trace(id + 1, hc, hr, h[id + 2]);
else {
long long opt = solve(id, hl, hc, hr);
if (opt ==
1 + solve(id, max(0LL, hl - b), max(0LL, hc - a), max(0LL, hr - b))) {
cout << id << " ";
return trace(id, max(0LL, hl - b), max(0LL, hc - a), max(0LL, hr - b));
} else {
return trace(id + 1, hc, hr, h[id + 2]);
}
}
}
int main() {
cin >> n >> a >> b;
for (long long i = 1; i <= n; i++) {
cin >> h[i];
h[i]++;
}
memset(dp, -1, sizeof dp);
long long ans = solve(2, h[1], h[2], h[3]);
cout << ans << endl;
trace(2, h[1], h[2], h[3]);
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, a, b;
long long h[20];
long long dp[20][20][20][20];
const long long INF = 1e16;
long long solve(long long id, long long hl, long long hc, long long hr) {
if (id == n) {
if (hc == 0 && hl == 0 && hr == 0) return 0;
return INF;
}
if (dp[id][hl][hc][hr] != -1) return dp[id][hl][hc][hr];
long long ret = 0;
if (hl == 0 && hc == 0 && hr == 0) {
ret = solve(id + 1, hc, hr, h[id + 2]);
} else {
ret = 1 + solve(id, max(0LL, hl - b), max(0LL, hc - a), max(0LL, hr - b));
if (hl == 0) {
ret = min(ret, solve(id + 1, hc, hr, h[id + 2]));
}
}
return dp[id][hl][hc][hr] = ret;
}
void trace(long long id, long long hl, long long hc, long long hr) {
if (id == n) {
return;
}
if (hl == 0 && hc == 0 && hr == 0)
return trace(id + 1, hc, hr, h[id + 2]);
else {
long long opt = solve(id, hl, hc, hr);
if (opt ==
1 + solve(id, max(0LL, hl - b), max(0LL, hc - a), max(0LL, hr - b))) {
cout << id << " ";
return trace(id, max(0LL, hl - b), max(0LL, hc - a), max(0LL, hr - b));
} else {
return trace(id + 1, hc, hr, h[id + 2]);
}
}
}
int main() {
cin >> n >> a >> b;
for (long long i = 1; i <= n; i++) {
cin >> h[i];
h[i]++;
}
memset(dp, -1, sizeof dp);
long long ans = solve(2, h[1], h[2], h[3]);
cout << ans << endl;
trace(2, h[1], h[2], h[3]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int dp[20][20][20][20];
int arr[20];
int n, a, b;
int func(int totake, int prv, int now, int nxt) {
if (totake == n) {
if (now > arr[totake] && prv > arr[totake - 1])
return 0;
else
return (1 << 29);
}
prv = min(prv, 19);
now = min(now, 19);
nxt = min(nxt, 19);
if (dp[totake][prv][now][nxt] != -1) return dp[totake][prv][now][nxt];
int ans = (1 << 29);
if (prv > arr[totake - 1]) {
ans = min(ans, func(totake + 1, now, nxt, 0));
}
for (int i = 1; true; ++i) {
if (prv + b * i > arr[totake - 1]) {
ans = min(ans, i + func(totake + 1, now + a * i, nxt + b * i, 0));
if (nxt + b * i > arr[totake + 1] && now + a * i > arr[totake]) break;
}
}
return dp[totake][prv][now][nxt] = ans;
}
vector<pair<int, int> > ans;
void pp(int totake, int prv, int now, int nxt) {
if (totake == n) {
return;
}
prv = min(prv, 19);
now = min(now, 19);
nxt = min(nxt, 19);
int &ret = dp[totake][prv][now][nxt];
if (prv > arr[totake - 1]) {
if (ret == func(totake + 1, now, nxt, 0)) {
pp(totake + 1, now, nxt, 0);
return;
}
}
for (int i = 1; true; ++i) {
if (prv + b * i > arr[totake - 1]) {
if (ret == i + func(totake + 1, now + a * i, nxt + b * i, 0)) {
ans.push_back(make_pair(totake, i));
pp(totake + 1, now + a * i, nxt + b * i, 0);
return;
}
if (nxt + b * i > arr[totake + 1] && now + a * i > arr[totake]) break;
}
}
return;
}
int main() {
memset((dp), -1, sizeof(dp));
;
for (int i = 0; i < 20; ++i) {
arr[i] = -100000;
}
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; ++i) {
scanf("%d", &arr[i]);
}
printf("%d\n", func(2, 0, 0, 0));
pp(2, 0, 0, 0);
for (int i = 0; i < ans.size(); ++i) {
for (int j = 0; j < ans[i].second; ++j) {
if (i || j) printf(" ");
printf("%d", ans[i].first);
}
}
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[20][20][20][20];
int arr[20];
int n, a, b;
int func(int totake, int prv, int now, int nxt) {
if (totake == n) {
if (now > arr[totake] && prv > arr[totake - 1])
return 0;
else
return (1 << 29);
}
prv = min(prv, 19);
now = min(now, 19);
nxt = min(nxt, 19);
if (dp[totake][prv][now][nxt] != -1) return dp[totake][prv][now][nxt];
int ans = (1 << 29);
if (prv > arr[totake - 1]) {
ans = min(ans, func(totake + 1, now, nxt, 0));
}
for (int i = 1; true; ++i) {
if (prv + b * i > arr[totake - 1]) {
ans = min(ans, i + func(totake + 1, now + a * i, nxt + b * i, 0));
if (nxt + b * i > arr[totake + 1] && now + a * i > arr[totake]) break;
}
}
return dp[totake][prv][now][nxt] = ans;
}
vector<pair<int, int> > ans;
void pp(int totake, int prv, int now, int nxt) {
if (totake == n) {
return;
}
prv = min(prv, 19);
now = min(now, 19);
nxt = min(nxt, 19);
int &ret = dp[totake][prv][now][nxt];
if (prv > arr[totake - 1]) {
if (ret == func(totake + 1, now, nxt, 0)) {
pp(totake + 1, now, nxt, 0);
return;
}
}
for (int i = 1; true; ++i) {
if (prv + b * i > arr[totake - 1]) {
if (ret == i + func(totake + 1, now + a * i, nxt + b * i, 0)) {
ans.push_back(make_pair(totake, i));
pp(totake + 1, now + a * i, nxt + b * i, 0);
return;
}
if (nxt + b * i > arr[totake + 1] && now + a * i > arr[totake]) break;
}
}
return;
}
int main() {
memset((dp), -1, sizeof(dp));
;
for (int i = 0; i < 20; ++i) {
arr[i] = -100000;
}
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; ++i) {
scanf("%d", &arr[i]);
}
printf("%d\n", func(2, 0, 0, 0));
pp(2, 0, 0, 0);
for (int i = 0; i < ans.size(); ++i) {
for (int j = 0; j < ans[i].second; ++j) {
if (i || j) printf(" ");
printf("%d", ans[i].first);
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h[22], t[22], s[22], out[22];
int i, a, b, n, ans;
int count(int s, int a) {
int ret = 0;
while (s >= 0) s -= a, ++ret;
return ret;
}
void dfs(int l, int sum) {
if (sum >= ans) return;
int i, tmp;
if (l == n) {
tmp = max(count(h[n] - s[n], b), count(h[n - 1] - s[n - 1], a));
if (ans > sum + tmp) {
ans = sum + tmp;
for (i = 2; i < n; ++i) out[i] = t[i];
out[n - 1] += tmp;
}
return;
}
tmp = count(h[l - 1] - s[l - 1], b);
if (tmp + sum >= ans) return;
s[l - 1] += b * (tmp - 1), s[l] += a * (tmp - 1), s[l + 1] += b * (tmp - 1);
for (i = tmp; i < 44; ++i) {
s[l - 1] += b, s[l] += a, s[l + 1] += b, t[l] = i;
dfs(l + 1, sum + i);
}
s[l - 1] -= b * (i - 1), s[l] -= a * (i - 1), s[l + 1] -= b * (i - 1);
}
int main() {
while (~scanf("%d%d%d", &n, &a, &b)) {
for (i = 1; i <= n; ++i) scanf("%d", &h[i]);
ans = 2e9;
memset(s, 0, sizeof(s));
memset(t, 0, sizeof(t));
dfs(2, 0);
printf("%d\n", ans);
for (i = 2; i < n; ++i)
while (out[i]--) printf("%d ", i);
puts("");
}
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h[22], t[22], s[22], out[22];
int i, a, b, n, ans;
int count(int s, int a) {
int ret = 0;
while (s >= 0) s -= a, ++ret;
return ret;
}
void dfs(int l, int sum) {
if (sum >= ans) return;
int i, tmp;
if (l == n) {
tmp = max(count(h[n] - s[n], b), count(h[n - 1] - s[n - 1], a));
if (ans > sum + tmp) {
ans = sum + tmp;
for (i = 2; i < n; ++i) out[i] = t[i];
out[n - 1] += tmp;
}
return;
}
tmp = count(h[l - 1] - s[l - 1], b);
if (tmp + sum >= ans) return;
s[l - 1] += b * (tmp - 1), s[l] += a * (tmp - 1), s[l + 1] += b * (tmp - 1);
for (i = tmp; i < 44; ++i) {
s[l - 1] += b, s[l] += a, s[l + 1] += b, t[l] = i;
dfs(l + 1, sum + i);
}
s[l - 1] -= b * (i - 1), s[l] -= a * (i - 1), s[l + 1] -= b * (i - 1);
}
int main() {
while (~scanf("%d%d%d", &n, &a, &b)) {
for (i = 1; i <= n; ++i) scanf("%d", &h[i]);
ans = 2e9;
memset(s, 0, sizeof(s));
memset(t, 0, sizeof(t));
dfs(2, 0);
printf("%d\n", ans);
for (i = 2; i < n; ++i)
while (out[i]--) printf("%d ", i);
puts("");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::istream;
using std::map;
using std::ostream;
using std::set;
using std::string;
using std::vector;
ostream &operator<<(ostream &os, const unsigned char v) {
os << (int)v;
return os;
}
istream &operator>>(istream &is, unsigned char &v) {
int tmp;
is >> tmp;
v = (unsigned char)tmp;
return is;
}
ostream &operator<<(ostream &os, const char v) {
os << (int)v;
return os;
}
istream &operator>>(istream &is, char &v) {
int tmp;
is >> tmp;
v = (char)tmp;
return is;
}
unsigned char n, a, b;
char h[10];
unsigned char fballs[10];
inline void fire(unsigned char i, unsigned char ntimes) {
h[i] -= ntimes * a;
h[i - 1] -= ntimes * b;
h[i + 1] -= ntimes * b;
}
inline void revFire(unsigned char i, unsigned char ntimes) {
h[i] += ntimes * a;
h[i - 1] += ntimes * b;
h[i + 1] += ntimes * b;
}
inline unsigned char min(unsigned char a, unsigned char b) {
return (a < b) ? a : b;
}
inline unsigned char max(unsigned char a, unsigned char b) {
return (a > b) ? a : b;
}
unsigned char dfs(unsigned char i, unsigned char e,
vector<unsigned char> &balls) {
if (i == e) {
unsigned char k = max((((h[i - 1]) < 0) ? 0 : ((h[i - 1]) / (b) + 1)),
(((h[i]) < 0) ? 0 : ((h[i]) / (a) + 1)));
balls[i] = k;
return k;
} else {
unsigned char ans = 161;
unsigned char selected_k = 0;
unsigned char fb = (((h[i - 1]) < 0) ? 0 : ((h[i - 1]) / (b) + 1));
unsigned char fa = (((h[i]) < 0) ? 0 : ((h[i]) / (a) + 1));
vector<unsigned char> tmp_balls(n);
for (unsigned char k = fb; k <= max(fb, fa); k += 1) {
fire(i, k);
unsigned char tmp = dfs(i + 1, e, tmp_balls);
if (tmp + k < ans) {
ans = tmp + k;
balls[i] = k;
for (unsigned char j = i + 1; j <= e; j++) {
balls[j] = tmp_balls[j];
}
}
revFire(i, k);
}
return (ans == 161) ? 0 : ans;
}
}
void dfsSearch(unsigned char i, unsigned char e) {
vector<unsigned char> balls(n);
dfs(i, e, balls);
for (int i = 1; i < n - 1; i++) {
fballs[i] += balls[i];
}
}
int main(int argc, const char *argv[]) {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
unsigned char balls = (((h[0]) < 0) ? 0 : ((h[0]) / (b) + 1));
fire(1, balls);
fballs[1] += balls;
balls = (((h[n - 1]) < 0) ? 0 : ((h[n - 1]) / (b) + 1));
fire(n - 2, balls);
fballs[n - 2] += balls;
dfsSearch(1, n - 2);
unsigned char ans = 0;
for (int i = 1; i < n - 1; i++) {
ans += fballs[i];
}
cout << ans << endl;
for (int i = 1; i < n - 1; i++) {
while (fballs[i] != 0) {
cout << i + 1 << " ";
fballs[i] -= 1;
}
}
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::istream;
using std::map;
using std::ostream;
using std::set;
using std::string;
using std::vector;
ostream &operator<<(ostream &os, const unsigned char v) {
os << (int)v;
return os;
}
istream &operator>>(istream &is, unsigned char &v) {
int tmp;
is >> tmp;
v = (unsigned char)tmp;
return is;
}
ostream &operator<<(ostream &os, const char v) {
os << (int)v;
return os;
}
istream &operator>>(istream &is, char &v) {
int tmp;
is >> tmp;
v = (char)tmp;
return is;
}
unsigned char n, a, b;
char h[10];
unsigned char fballs[10];
inline void fire(unsigned char i, unsigned char ntimes) {
h[i] -= ntimes * a;
h[i - 1] -= ntimes * b;
h[i + 1] -= ntimes * b;
}
inline void revFire(unsigned char i, unsigned char ntimes) {
h[i] += ntimes * a;
h[i - 1] += ntimes * b;
h[i + 1] += ntimes * b;
}
inline unsigned char min(unsigned char a, unsigned char b) {
return (a < b) ? a : b;
}
inline unsigned char max(unsigned char a, unsigned char b) {
return (a > b) ? a : b;
}
unsigned char dfs(unsigned char i, unsigned char e,
vector<unsigned char> &balls) {
if (i == e) {
unsigned char k = max((((h[i - 1]) < 0) ? 0 : ((h[i - 1]) / (b) + 1)),
(((h[i]) < 0) ? 0 : ((h[i]) / (a) + 1)));
balls[i] = k;
return k;
} else {
unsigned char ans = 161;
unsigned char selected_k = 0;
unsigned char fb = (((h[i - 1]) < 0) ? 0 : ((h[i - 1]) / (b) + 1));
unsigned char fa = (((h[i]) < 0) ? 0 : ((h[i]) / (a) + 1));
vector<unsigned char> tmp_balls(n);
for (unsigned char k = fb; k <= max(fb, fa); k += 1) {
fire(i, k);
unsigned char tmp = dfs(i + 1, e, tmp_balls);
if (tmp + k < ans) {
ans = tmp + k;
balls[i] = k;
for (unsigned char j = i + 1; j <= e; j++) {
balls[j] = tmp_balls[j];
}
}
revFire(i, k);
}
return (ans == 161) ? 0 : ans;
}
}
void dfsSearch(unsigned char i, unsigned char e) {
vector<unsigned char> balls(n);
dfs(i, e, balls);
for (int i = 1; i < n - 1; i++) {
fballs[i] += balls[i];
}
}
int main(int argc, const char *argv[]) {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
unsigned char balls = (((h[0]) < 0) ? 0 : ((h[0]) / (b) + 1));
fire(1, balls);
fballs[1] += balls;
balls = (((h[n - 1]) < 0) ? 0 : ((h[n - 1]) / (b) + 1));
fire(n - 2, balls);
fballs[n - 2] += balls;
dfsSearch(1, n - 2);
unsigned char ans = 0;
for (int i = 1; i < n - 1; i++) {
ans += fballs[i];
}
cout << ans << endl;
for (int i = 1; i < n - 1; i++) {
while (fballs[i] != 0) {
cout << i + 1 << " ";
fballs[i] -= 1;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int dp[12][16][16][16], pre[12][4096];
vector<int> v;
int main() {
int n, a, b, i, h[12], tp, ans, tq;
bool flg = false;
scanf("%d%d%d", &n, &a, &b);
for (i = 1; i <= n; i++) scanf("%d", &h[i]);
ans = tp = h[1] / b + 1;
for (i = 0; i < tp; i++) v.push_back(2);
h[1] -= tp * b;
h[2] -= tp * a;
h[3] -= tp * b;
if (h[n] > 0) {
tp = h[n] / b + 1;
h[n] -= tp * b;
h[n - 1] -= tp * a;
h[n - 2] -= tp * b;
ans += tp;
for (i = 0; i < tp; i++) v.push_back(n - 1);
}
memset(dp, 0x10, sizeof(dp));
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++)
for (int l = 0; l <= 15; l++) dp[1][j][k][l] = j + k + l;
tp = 0xffff;
for (i = 2; i <= n; i++) {
if (h[i] >= 0) flg = true;
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++)
for (int l = 0; l <= 15; l++) {
if (j * b + k * a + l * b > h[i - 1]) {
for (int m = 0; m <= 15; m++) {
if (dp[i][j][k][l] > dp[i - 1][m][j][k] + l) {
dp[i][j][k][l] = dp[i - 1][m][j][k] + l;
pre[i][j * 256 + k * 16 + l] = m * 256 + j * 16 + k;
}
if (i == n)
if (tp > dp[i][j][k][l]) {
tq = m * 256 + j * 16 + k;
tp = dp[i][j][k][l];
}
}
}
}
}
if (flg) {
i = n;
while (i >= 2) {
tp = tq % 16;
for (int j = 0; j < tp; j++) v.push_back(i - 1);
tq = pre[--i][tq];
}
}
printf("%d\n", v.size());
printf("%d", v[0]);
for (i = 1; i < v.size(); i++) printf(" %d", v[i]);
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[12][16][16][16], pre[12][4096];
vector<int> v;
int main() {
int n, a, b, i, h[12], tp, ans, tq;
bool flg = false;
scanf("%d%d%d", &n, &a, &b);
for (i = 1; i <= n; i++) scanf("%d", &h[i]);
ans = tp = h[1] / b + 1;
for (i = 0; i < tp; i++) v.push_back(2);
h[1] -= tp * b;
h[2] -= tp * a;
h[3] -= tp * b;
if (h[n] > 0) {
tp = h[n] / b + 1;
h[n] -= tp * b;
h[n - 1] -= tp * a;
h[n - 2] -= tp * b;
ans += tp;
for (i = 0; i < tp; i++) v.push_back(n - 1);
}
memset(dp, 0x10, sizeof(dp));
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++)
for (int l = 0; l <= 15; l++) dp[1][j][k][l] = j + k + l;
tp = 0xffff;
for (i = 2; i <= n; i++) {
if (h[i] >= 0) flg = true;
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++)
for (int l = 0; l <= 15; l++) {
if (j * b + k * a + l * b > h[i - 1]) {
for (int m = 0; m <= 15; m++) {
if (dp[i][j][k][l] > dp[i - 1][m][j][k] + l) {
dp[i][j][k][l] = dp[i - 1][m][j][k] + l;
pre[i][j * 256 + k * 16 + l] = m * 256 + j * 16 + k;
}
if (i == n)
if (tp > dp[i][j][k][l]) {
tq = m * 256 + j * 16 + k;
tp = dp[i][j][k][l];
}
}
}
}
}
if (flg) {
i = n;
while (i >= 2) {
tp = tq % 16;
for (int j = 0; j < tp; j++) v.push_back(i - 1);
tq = pre[--i][tq];
}
}
printf("%d\n", v.size());
printf("%d", v[0]);
for (i = 1; i < v.size(); i++) printf(" %d", v[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int dp[15][20][20], n, a, b, h[20];
int X[15][20][20], Y[15][20][20];
void output(int dep, int x, int y) {
if (dep == 2) return;
output(dep - 1, X[dep][x][y], Y[dep][x][y]);
for (int i = 0; i < dp[dep][x][y] - dp[dep - 1][X[dep][x][y]][Y[dep][x][y]];
i++)
printf("%d ", dep - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 16; j++)
for (int k = 0; k <= 16; k++) dp[i][j][k] = 1e9;
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == 1e9) continue;
int from = (j + b - 1) / b;
int to = max(from, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = from; hit <= to; hit++) {
if (dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] >
dp[i][j][k] + hit) {
dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] =
dp[i][j][k] + hit;
X[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = j;
Y[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = k;
}
}
}
}
}
printf("%d\n", dp[n][0][0]);
output(n, 0, 0);
puts("");
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[15][20][20], n, a, b, h[20];
int X[15][20][20], Y[15][20][20];
void output(int dep, int x, int y) {
if (dep == 2) return;
output(dep - 1, X[dep][x][y], Y[dep][x][y]);
for (int i = 0; i < dp[dep][x][y] - dp[dep - 1][X[dep][x][y]][Y[dep][x][y]];
i++)
printf("%d ", dep - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 16; j++)
for (int k = 0; k <= 16; k++) dp[i][j][k] = 1e9;
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == 1e9) continue;
int from = (j + b - 1) / b;
int to = max(from, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = from; hit <= to; hit++) {
if (dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] >
dp[i][j][k] + hit) {
dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] =
dp[i][j][k] + hit;
X[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = j;
Y[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = k;
}
}
}
}
}
printf("%d\n", dp[n][0][0]);
output(n, 0, 0);
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n, a, b;
int h[N];
map<pair<pair<int, int>, int>, int> dp;
map<pair<pair<int, int>, int>, int> pick;
int needs(int hp, int damage) {
if (hp < 0) return 0;
return hp / damage + 1;
}
int hit(int id, int n, bool hitPrev = false) {
for (int i = -1; i <= +1; i++) {
if (i >= 0 || hitPrev) {
h[id + i] -= (i == 0 ? a : b) * n;
if (h[id + i] < 0) h[id + i] = -1;
}
}
return n;
}
int go(int id, int minHits) {
pair<pair<int, int>, int> key = make_pair(make_pair(id, h[id]), minHits);
if (dp.find(key) != dp.end()) return dp[key];
if (id == n - 2) {
int best = max(minHits, needs(h[id], a));
dp[key] = best;
pick[key] = best;
return best;
}
int best = 0x7fffffff;
int p = -1;
for (int x = max(minHits, needs(h[id], a)); x >= minHits; x--) {
int save[2];
for (int i = 0; i < 2; i++) save[i] = h[id + i];
hit(id, x);
int cost = x + go(id + 1, needs(h[id], b));
if (cost < best) {
best = cost;
p = x;
}
for (int i = 0; i < 2; i++) h[id + i] = save[i];
}
pick[key] = p;
return dp[key] = best;
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) cin >> h[i];
vector<int> r;
for (int i = hit(1, needs(h[0], b), true); i--;) r.push_back(2);
for (int i = hit(n - 2, needs(h[n - 1], b), true); i--;) r.push_back(n - 1);
go(1, 0);
int id = 1, minHits = 0;
while (id < n - 1) {
pair<pair<int, int>, int> key = make_pair(make_pair(id, h[id]), minHits);
int x = pick[key];
hit(id, x);
minHits = needs(h[id], b);
id++;
while (x--) r.push_back(id);
}
cout << r.size() << endl;
for (int i = 0; i < r.size(); i++) {
if (i > 0) cout << ' ';
cout << r[i];
}
cout << endl;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n, a, b;
int h[N];
map<pair<pair<int, int>, int>, int> dp;
map<pair<pair<int, int>, int>, int> pick;
int needs(int hp, int damage) {
if (hp < 0) return 0;
return hp / damage + 1;
}
int hit(int id, int n, bool hitPrev = false) {
for (int i = -1; i <= +1; i++) {
if (i >= 0 || hitPrev) {
h[id + i] -= (i == 0 ? a : b) * n;
if (h[id + i] < 0) h[id + i] = -1;
}
}
return n;
}
int go(int id, int minHits) {
pair<pair<int, int>, int> key = make_pair(make_pair(id, h[id]), minHits);
if (dp.find(key) != dp.end()) return dp[key];
if (id == n - 2) {
int best = max(minHits, needs(h[id], a));
dp[key] = best;
pick[key] = best;
return best;
}
int best = 0x7fffffff;
int p = -1;
for (int x = max(minHits, needs(h[id], a)); x >= minHits; x--) {
int save[2];
for (int i = 0; i < 2; i++) save[i] = h[id + i];
hit(id, x);
int cost = x + go(id + 1, needs(h[id], b));
if (cost < best) {
best = cost;
p = x;
}
for (int i = 0; i < 2; i++) h[id + i] = save[i];
}
pick[key] = p;
return dp[key] = best;
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) cin >> h[i];
vector<int> r;
for (int i = hit(1, needs(h[0], b), true); i--;) r.push_back(2);
for (int i = hit(n - 2, needs(h[n - 1], b), true); i--;) r.push_back(n - 1);
go(1, 0);
int id = 1, minHits = 0;
while (id < n - 1) {
pair<pair<int, int>, int> key = make_pair(make_pair(id, h[id]), minHits);
int x = pick[key];
hit(id, x);
minHits = needs(h[id], b);
id++;
while (x--) r.push_back(id);
}
cout << r.size() << endl;
for (int i = 0; i < r.size(); i++) {
if (i > 0) cout << ' ';
cout << r[i];
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
const int maxn = 1000;
int n, a, b;
int h[maxn];
int cur[maxn];
int now[maxn];
int ans = maxn;
bool dfs(int who, int num) {
int i, j;
if (num >= ans) return false;
if (who == n) {
if (h[n] >= 0) return false;
ans = num;
for (i = 2; i < n; i++) now[i] = cur[i];
return true;
} else {
int begin = ((h[who - 1] + b - 1) / b);
if (begin < 0) begin = 0;
for (j = begin; j <= 16; j++)
if (h[who - 1] - b * j >= 0)
continue;
else {
if (j + num >= ans) break;
if (who == n - 1 && h[who + 1] - b * j >= 0) continue;
cur[who] = j;
h[who - 1] -= b * j;
h[who] -= a * j;
h[who + 1] -= b * j;
bool ok = dfs(who + 1, num + j);
h[who - 1] += b * j;
h[who] += a * j;
h[who + 1] += b * j;
if (h[who - 1] - b * j < 0 && h[who + 1] - b * j < 0 &&
h[who] - a * j < 0)
break;
}
}
return false;
}
int main() {
int i, j, sum = 0;
scanf("%d%d%d", &n, &a, &b);
for (i = 1; i <= n; i++) scanf("%d", h + i);
dfs(2, 0);
printf("%d\n", ans);
for (i = 1; i <= n; i++)
for (j = 1; j <= now[i]; j++) {
sum++;
if (sum == ans)
printf("%d\n", i);
else
printf("%d ", i);
}
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
const int maxn = 1000;
int n, a, b;
int h[maxn];
int cur[maxn];
int now[maxn];
int ans = maxn;
bool dfs(int who, int num) {
int i, j;
if (num >= ans) return false;
if (who == n) {
if (h[n] >= 0) return false;
ans = num;
for (i = 2; i < n; i++) now[i] = cur[i];
return true;
} else {
int begin = ((h[who - 1] + b - 1) / b);
if (begin < 0) begin = 0;
for (j = begin; j <= 16; j++)
if (h[who - 1] - b * j >= 0)
continue;
else {
if (j + num >= ans) break;
if (who == n - 1 && h[who + 1] - b * j >= 0) continue;
cur[who] = j;
h[who - 1] -= b * j;
h[who] -= a * j;
h[who + 1] -= b * j;
bool ok = dfs(who + 1, num + j);
h[who - 1] += b * j;
h[who] += a * j;
h[who + 1] += b * j;
if (h[who - 1] - b * j < 0 && h[who + 1] - b * j < 0 &&
h[who] - a * j < 0)
break;
}
}
return false;
}
int main() {
int i, j, sum = 0;
scanf("%d%d%d", &n, &a, &b);
for (i = 1; i <= n; i++) scanf("%d", h + i);
dfs(2, 0);
printf("%d\n", ans);
for (i = 1; i <= n; i++)
for (j = 1; j <= now[i]; j++) {
sum++;
if (sum == ans)
printf("%d\n", i);
else
printf("%d ", i);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, ans = 0x7FFFFFFF, tn = 0;
int h[20];
int p[20], pp[20];
bool f[20][100][150][20];
void DFS(int id, int times, int now) {
if (f[id][now + 60][tn][times]) return;
f[id][now + 60][tn][times] = true;
if (id == n) {
if (now < 0 && tn <= ans) {
ans = tn;
memcpy(pp, p, sizeof(p));
}
return;
}
for (int i = times;; i++) {
int npre = now - a * i;
int times = 0;
if (npre >= 0) times = npre / b + 1;
int nnow = h[id + 1] - b * i;
p[id] = i;
tn += i;
DFS(id + 1, times, nnow);
tn -= i;
p[id] = 0;
if (npre < 0 && nnow < 0) break;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
memset(f, 0, sizeof(f));
int times = 0;
if (h[1] >= 0) times = h[1] / b + 1;
DFS(2, times, h[2]);
cout << ans << endl;
for (int i = 2; i <= n; i++)
for (int j = 0; j < pp[i]; j++) printf("%d ", i);
puts("");
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, ans = 0x7FFFFFFF, tn = 0;
int h[20];
int p[20], pp[20];
bool f[20][100][150][20];
void DFS(int id, int times, int now) {
if (f[id][now + 60][tn][times]) return;
f[id][now + 60][tn][times] = true;
if (id == n) {
if (now < 0 && tn <= ans) {
ans = tn;
memcpy(pp, p, sizeof(p));
}
return;
}
for (int i = times;; i++) {
int npre = now - a * i;
int times = 0;
if (npre >= 0) times = npre / b + 1;
int nnow = h[id + 1] - b * i;
p[id] = i;
tn += i;
DFS(id + 1, times, nnow);
tn -= i;
p[id] = 0;
if (npre < 0 && nnow < 0) break;
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
memset(f, 0, sizeof(f));
int times = 0;
if (h[1] >= 0) times = h[1] / b + 1;
DFS(2, times, h[2]);
cout << ans << endl;
for (int i = 2; i <= n; i++)
for (int j = 0; j < pp[i]; j++) printf("%d ", i);
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h[20];
int dp[20][20][20];
int cntL[20][20][20], cntM[20][20][20];
vector<int> v;
int main() {
int i, j, k, n, a, b, l, m;
cin >> n >> a >> b;
for (i = 0; i < n; i++) cin >> h[i];
int cnt = 0;
while (h[0] >= 0) {
h[0] -= b;
h[1] -= a;
h[2] -= b;
v.push_back(2);
cnt++;
}
while (h[n - 1] >= 0) {
h[n - 1] -= b;
h[n - 2] -= a;
h[n - 3] -= b;
v.push_back(n - 1);
cnt++;
}
for (i = 1; i <= n - 2; i++) {
if (h[i] >= 0) h[i]++;
}
for (i = 0; i <= n - 2; i++)
for (j = 0; j <= 16; j++)
for (k = 0; k <= 16; k++) dp[i][j][k] = INT_MAX;
dp[0][0][0] = 0;
for (i = 1; i <= n - 2; i++)
for (j = 0; j <= 16; j++) {
for (l = 0; l <= 16; l++)
for (m = 0; m <= 16; m++) {
if (dp[i - 1][l][m] != INT_MAX && l - j * b <= 0) {
int lft = max(0, h[i] - m * b - a * j);
if (dp[i][lft][j] > dp[i - 1][l][m] + j) {
dp[i][lft][j] = dp[i - 1][l][m] + j;
cntL[i][lft][j] = l;
cntM[i][lft][j] = m;
}
}
}
}
int ans = INT_MAX;
int idxL = -1, idxM = -1;
for (i = 0; i <= 16; i++) {
if (ans > dp[n - 2][0][i]) {
ans = dp[n - 2][0][i];
idxL = 0;
idxM = i;
}
}
for (i = n - 2; i > 0; i--) {
for (j = 0; j < idxM; j++) {
v.push_back(i + 1);
}
int tIdxL = cntL[i][idxL][idxM];
int tIdxM = cntM[i][idxL][idxM];
idxL = tIdxL;
idxM = tIdxM;
}
cout << ans + cnt << endl;
for (i = 0; i < v.size(); i++) cout << v[i] << " ";
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h[20];
int dp[20][20][20];
int cntL[20][20][20], cntM[20][20][20];
vector<int> v;
int main() {
int i, j, k, n, a, b, l, m;
cin >> n >> a >> b;
for (i = 0; i < n; i++) cin >> h[i];
int cnt = 0;
while (h[0] >= 0) {
h[0] -= b;
h[1] -= a;
h[2] -= b;
v.push_back(2);
cnt++;
}
while (h[n - 1] >= 0) {
h[n - 1] -= b;
h[n - 2] -= a;
h[n - 3] -= b;
v.push_back(n - 1);
cnt++;
}
for (i = 1; i <= n - 2; i++) {
if (h[i] >= 0) h[i]++;
}
for (i = 0; i <= n - 2; i++)
for (j = 0; j <= 16; j++)
for (k = 0; k <= 16; k++) dp[i][j][k] = INT_MAX;
dp[0][0][0] = 0;
for (i = 1; i <= n - 2; i++)
for (j = 0; j <= 16; j++) {
for (l = 0; l <= 16; l++)
for (m = 0; m <= 16; m++) {
if (dp[i - 1][l][m] != INT_MAX && l - j * b <= 0) {
int lft = max(0, h[i] - m * b - a * j);
if (dp[i][lft][j] > dp[i - 1][l][m] + j) {
dp[i][lft][j] = dp[i - 1][l][m] + j;
cntL[i][lft][j] = l;
cntM[i][lft][j] = m;
}
}
}
}
int ans = INT_MAX;
int idxL = -1, idxM = -1;
for (i = 0; i <= 16; i++) {
if (ans > dp[n - 2][0][i]) {
ans = dp[n - 2][0][i];
idxL = 0;
idxM = i;
}
}
for (i = n - 2; i > 0; i--) {
for (j = 0; j < idxM; j++) {
v.push_back(i + 1);
}
int tIdxL = cntL[i][idxL][idxM];
int tIdxM = cntM[i][idxL][idxM];
idxL = tIdxL;
idxM = tIdxM;
}
cout << ans + cnt << endl;
for (i = 0; i < v.size(); i++) cout << v[i] << " ";
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct Node {
pair<int, pair<char, char>>* ptr;
bool valid;
int num;
char a, b, f, s;
Node() {
num = 1000;
valid = false;
a = b = f = s = 0;
ptr = 0;
}
};
int a, b, N;
int h[10];
Node dt[17][17][10];
pair<int, pair<char, char>>* Current;
pair<int, pair<char, char>>* Next;
pair<int, pair<char, char>> _current[255];
pair<int, pair<char, char>> _next[255];
int icur = 0, inext = 0;
int main() {
cin >> N >> a >> b;
for (int i = 0; i < N; i++) {
cin >> h[i];
h[i]++;
}
int t1, t2, t3, t4, A, B, v, w;
Current = &_current[0], Next = &_next[0];
B = (h[N - 1] / b) + bool(h[N - 1] % b);
h[N - 1] = 0;
t1 = h[N - 2] - (a * B);
if (t1 < 0) t1 = 0;
h[N - 2] = t1;
t2 = h[N - 3] - (b * B);
if (t2 < 0) t2 = 0;
h[N - 3] = t2;
int _a = B;
B = (h[0] / b) + bool(h[0] % b);
t1 = h[1] - (a * B);
if (t1 < 0) t1 = 0;
h[1] = t1;
t2 = h[2] - (b * B);
if (t2 < 0) t2 = 0;
h[2] = t2;
dt[t1][t2][1].num = B, dt[t1][t2][1].valid = true, dt[t1][t2][1].a = B;
Current[icur].first = B;
Current[icur++].second = pair<char, char>(t1, t2);
for (int k = 1; k < N - 2; k++) {
for (int j = 0; j < icur; j++) {
v = Current[j].second.first;
w = Current[j].second.second;
A = B = 0;
while (1) {
t1 = v, t2 = w, t3 = h[k + 2], t4 = dt[v][w][k].num;
B = (v - A);
if (B > 0)
B = (B / b) + bool(B % b);
else
B = 0;
for (int i1 = 0; i1 < B; i1++) {
t1 -= b, t2 -= a, t3 -= b;
t4++;
(t1 < 0) ? (t1 = 0) : true, (t2 < 0) ? (t2 = 0) : true,
(t3 < 0) ? (t3 = 0) : true;
}
for (int j1 = 0; j1 < A; j1 += a) {
t1 -= a, t2 -= b, t4++;
(t1 < 0) ? (t1 = 0) : true, (t2 < 0) ? (t2 = 0) : true;
}
if (dt[t2][t3][k + 1].num > t4) {
dt[t2][t3][k + 1].num = t4;
dt[t2][t3][k + 1].valid = true;
dt[t2][t3][k + 1].a = B;
dt[t2][t3][k + 1].b = A / a;
dt[t2][t3][k + 1].f = v, dt[t2][t3][k + 1].s = w;
pair<int, pair<char, char>>* p = dt[t2][t3][k + 1].ptr;
if (!p) {
p = dt[t2][t3][k + 1].ptr = &Next[inext++];
(*p).second = pair<char, char>(t2, t3);
}
(*p).first = t4;
}
if (B <= 0) break;
A += a;
}
}
swap<pair<int, pair<char, char>>*>(Current, Next);
icur = inext;
inext = 0;
std::sort<pair<int, pair<char, char>>*>(Current, Current + icur);
}
t1 = 10000;
pair<int, int> temp;
for (int i = 0; i < icur; i++) {
v = Current[i].second.first, w = Current[i].second.second;
A = (v / a) + bool(v % a);
t2 = A + Current[i].first;
if (t1 > t2) {
t1 = t2;
temp.first = v, temp.second = w;
dt[v][w][N - 2].a += A;
dt[v][w][N - 2].num = t2;
}
}
v = temp.first, w = temp.second;
dt[v][w][N - 2].a += _a;
cout << dt[v][w][N - 2].num + _a << '\n';
Node _temp;
for (int q = N - 2; q > 0; q--) {
_temp = dt[v][w][q];
for (int i = 0; i < _temp.a; i++) cout << q + 1 << ' ';
dt[_temp.f][_temp.s][q - 1].a += _temp.b;
v = _temp.f, w = _temp.s;
}
cout << '\n';
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct Node {
pair<int, pair<char, char>>* ptr;
bool valid;
int num;
char a, b, f, s;
Node() {
num = 1000;
valid = false;
a = b = f = s = 0;
ptr = 0;
}
};
int a, b, N;
int h[10];
Node dt[17][17][10];
pair<int, pair<char, char>>* Current;
pair<int, pair<char, char>>* Next;
pair<int, pair<char, char>> _current[255];
pair<int, pair<char, char>> _next[255];
int icur = 0, inext = 0;
int main() {
cin >> N >> a >> b;
for (int i = 0; i < N; i++) {
cin >> h[i];
h[i]++;
}
int t1, t2, t3, t4, A, B, v, w;
Current = &_current[0], Next = &_next[0];
B = (h[N - 1] / b) + bool(h[N - 1] % b);
h[N - 1] = 0;
t1 = h[N - 2] - (a * B);
if (t1 < 0) t1 = 0;
h[N - 2] = t1;
t2 = h[N - 3] - (b * B);
if (t2 < 0) t2 = 0;
h[N - 3] = t2;
int _a = B;
B = (h[0] / b) + bool(h[0] % b);
t1 = h[1] - (a * B);
if (t1 < 0) t1 = 0;
h[1] = t1;
t2 = h[2] - (b * B);
if (t2 < 0) t2 = 0;
h[2] = t2;
dt[t1][t2][1].num = B, dt[t1][t2][1].valid = true, dt[t1][t2][1].a = B;
Current[icur].first = B;
Current[icur++].second = pair<char, char>(t1, t2);
for (int k = 1; k < N - 2; k++) {
for (int j = 0; j < icur; j++) {
v = Current[j].second.first;
w = Current[j].second.second;
A = B = 0;
while (1) {
t1 = v, t2 = w, t3 = h[k + 2], t4 = dt[v][w][k].num;
B = (v - A);
if (B > 0)
B = (B / b) + bool(B % b);
else
B = 0;
for (int i1 = 0; i1 < B; i1++) {
t1 -= b, t2 -= a, t3 -= b;
t4++;
(t1 < 0) ? (t1 = 0) : true, (t2 < 0) ? (t2 = 0) : true,
(t3 < 0) ? (t3 = 0) : true;
}
for (int j1 = 0; j1 < A; j1 += a) {
t1 -= a, t2 -= b, t4++;
(t1 < 0) ? (t1 = 0) : true, (t2 < 0) ? (t2 = 0) : true;
}
if (dt[t2][t3][k + 1].num > t4) {
dt[t2][t3][k + 1].num = t4;
dt[t2][t3][k + 1].valid = true;
dt[t2][t3][k + 1].a = B;
dt[t2][t3][k + 1].b = A / a;
dt[t2][t3][k + 1].f = v, dt[t2][t3][k + 1].s = w;
pair<int, pair<char, char>>* p = dt[t2][t3][k + 1].ptr;
if (!p) {
p = dt[t2][t3][k + 1].ptr = &Next[inext++];
(*p).second = pair<char, char>(t2, t3);
}
(*p).first = t4;
}
if (B <= 0) break;
A += a;
}
}
swap<pair<int, pair<char, char>>*>(Current, Next);
icur = inext;
inext = 0;
std::sort<pair<int, pair<char, char>>*>(Current, Current + icur);
}
t1 = 10000;
pair<int, int> temp;
for (int i = 0; i < icur; i++) {
v = Current[i].second.first, w = Current[i].second.second;
A = (v / a) + bool(v % a);
t2 = A + Current[i].first;
if (t1 > t2) {
t1 = t2;
temp.first = v, temp.second = w;
dt[v][w][N - 2].a += A;
dt[v][w][N - 2].num = t2;
}
}
v = temp.first, w = temp.second;
dt[v][w][N - 2].a += _a;
cout << dt[v][w][N - 2].num + _a << '\n';
Node _temp;
for (int q = N - 2; q > 0; q--) {
_temp = dt[v][w][q];
for (int i = 0; i < _temp.a; i++) cout << q + 1 << ' ';
dt[_temp.f][_temp.s][q - 1].a += _temp.b;
v = _temp.f, w = _temp.s;
}
cout << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
vector<int> vec, temp, best;
void solve(int idx) {
if (idx == n) {
int c = 0;
while (vec[idx] > 0 || vec[idx - 1] > 0)
++c, vec[idx] -= a, vec[idx - 1] -= b, temp.push_back(idx + 1);
if ((!best.size()) || best.size() > temp.size()) best = temp;
while (c--) vec[idx] += a, vec[idx - 1] += b, temp.pop_back();
return;
}
if (vec[idx] > 0 || vec[idx - 1] > 0) {
vec[idx] -= a;
vec[idx - 1] -= b;
vec[idx + 1] -= b;
temp.push_back(idx + 1);
solve(idx);
temp.pop_back();
vec[idx] += a;
vec[idx - 1] += b;
vec[idx + 1] += b;
}
if (vec[idx - 1] <= 0) solve(idx + 1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
vec = vector<int>(n);
for (auto i = 0; i < (long long)(n); i++) cin >> vec[i], vec[i]++;
vector<int> res;
while (vec[0] > 0) vec[1] -= a, vec[2] -= b, vec[0] -= b, res.push_back(2);
while (vec[n - 1] > 0)
vec[n - 1] -= b, vec[n - 2] -= a, vec[n - 3] -= b, res.push_back(n - 1);
n -= 2;
solve(1);
cout << ((int)((res).size())) + ((int)((best).size())) << '\n';
for (auto i : res) cout << i << " ";
for (auto i : best) cout << i << " ";
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
vector<int> vec, temp, best;
void solve(int idx) {
if (idx == n) {
int c = 0;
while (vec[idx] > 0 || vec[idx - 1] > 0)
++c, vec[idx] -= a, vec[idx - 1] -= b, temp.push_back(idx + 1);
if ((!best.size()) || best.size() > temp.size()) best = temp;
while (c--) vec[idx] += a, vec[idx - 1] += b, temp.pop_back();
return;
}
if (vec[idx] > 0 || vec[idx - 1] > 0) {
vec[idx] -= a;
vec[idx - 1] -= b;
vec[idx + 1] -= b;
temp.push_back(idx + 1);
solve(idx);
temp.pop_back();
vec[idx] += a;
vec[idx - 1] += b;
vec[idx + 1] += b;
}
if (vec[idx - 1] <= 0) solve(idx + 1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
vec = vector<int>(n);
for (auto i = 0; i < (long long)(n); i++) cin >> vec[i], vec[i]++;
vector<int> res;
while (vec[0] > 0) vec[1] -= a, vec[2] -= b, vec[0] -= b, res.push_back(2);
while (vec[n - 1] > 0)
vec[n - 1] -= b, vec[n - 2] -= a, vec[n - 3] -= b, res.push_back(n - 1);
n -= 2;
solve(1);
cout << ((int)((res).size())) + ((int)((best).size())) << '\n';
for (auto i : res) cout << i << " ";
for (auto i : best) cout << i << " ";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[15];
int dp[20][20][20][20], g1[20][20][20][20], g2[20][20][20][20],
g3[20][20][20][20];
void hg(int a1, int a2, int a3, int a4) {
if (a1 == 0) {
return;
}
for (int i = 0; i < a4; i++) {
printf("%d ", a1 + 1);
}
hg(a1 - 1, g1[a1][a2][a3][a4], g2[a1][a2][a3][a4], g3[a1][a2][a3][a4]);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
memset(dp, -1, sizeof(dp));
memset(g1, -1, sizeof(g1));
memset(g2, -1, sizeof(g2));
memset(g3, -1, sizeof(g3));
for (int i = 19; i >= 0; i--) {
if (h[0] - i * b > 0) {
break;
}
dp[1][max(0, h[1] - i * a)][max(0, h[2] - i * b)][i] = i;
}
for (int i = 1; i < n - 1; i++) {
for (int j = 0; j <= h[i]; j++) {
for (int k = 0; k <= h[i + 1]; k++) {
for (int l = 0; l < 20; l++) {
if (dp[i][j][k][l] == -1) {
continue;
}
for (int m = 19; m >= 0; m--) {
if (j - m * b > 0) {
break;
}
int a1 = i + 1, a2 = max(0, k - m * a),
a3 = max(0, h[i + 2] - m * b), a4 = m;
if (dp[a1][a2][a3][a4] == -1 ||
dp[a1][a2][a3][a4] > dp[i][j][k][l] + m) {
dp[a1][a2][a3][a4] = dp[i][j][k][l] + m;
g1[a1][a2][a3][a4] = j;
g2[a1][a2][a3][a4] = k;
g3[a1][a2][a3][a4] = l;
}
}
}
}
}
}
int mu = 19;
for (int i = 0; i <= 19; i++) {
if (dp[n - 2][0][0][i] != -1 && dp[n - 2][0][0][mu] > dp[n - 2][0][0][i]) {
mu = i;
}
}
printf("%d\n", dp[n - 2][0][0][mu]);
hg(n - 2, 0, 0, mu);
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[15];
int dp[20][20][20][20], g1[20][20][20][20], g2[20][20][20][20],
g3[20][20][20][20];
void hg(int a1, int a2, int a3, int a4) {
if (a1 == 0) {
return;
}
for (int i = 0; i < a4; i++) {
printf("%d ", a1 + 1);
}
hg(a1 - 1, g1[a1][a2][a3][a4], g2[a1][a2][a3][a4], g3[a1][a2][a3][a4]);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
memset(dp, -1, sizeof(dp));
memset(g1, -1, sizeof(g1));
memset(g2, -1, sizeof(g2));
memset(g3, -1, sizeof(g3));
for (int i = 19; i >= 0; i--) {
if (h[0] - i * b > 0) {
break;
}
dp[1][max(0, h[1] - i * a)][max(0, h[2] - i * b)][i] = i;
}
for (int i = 1; i < n - 1; i++) {
for (int j = 0; j <= h[i]; j++) {
for (int k = 0; k <= h[i + 1]; k++) {
for (int l = 0; l < 20; l++) {
if (dp[i][j][k][l] == -1) {
continue;
}
for (int m = 19; m >= 0; m--) {
if (j - m * b > 0) {
break;
}
int a1 = i + 1, a2 = max(0, k - m * a),
a3 = max(0, h[i + 2] - m * b), a4 = m;
if (dp[a1][a2][a3][a4] == -1 ||
dp[a1][a2][a3][a4] > dp[i][j][k][l] + m) {
dp[a1][a2][a3][a4] = dp[i][j][k][l] + m;
g1[a1][a2][a3][a4] = j;
g2[a1][a2][a3][a4] = k;
g3[a1][a2][a3][a4] = l;
}
}
}
}
}
}
int mu = 19;
for (int i = 0; i <= 19; i++) {
if (dp[n - 2][0][0][i] != -1 && dp[n - 2][0][0][mu] > dp[n - 2][0][0][i]) {
mu = i;
}
}
printf("%d\n", dp[n - 2][0][0][mu]);
hg(n - 2, 0, 0, mu);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15 + 2;
int n, a, b, h[maxn], ans = 0x7fffffff;
vector<int> hit, tmp;
void health(int c, int a, int b) {
h[c - 1] -= b;
h[c + 1] -= b;
h[c] -= a;
return;
}
void dfs(int c, int times) {
if (times >= ans) return;
if (c == n) {
if (h[n] < 0) {
ans = times;
hit = tmp;
}
return;
}
for (int i = 0;
i <= max(h[c - 1] / b + 1, max(h[c] / a + 1, h[c + 1] / b + 1)); i++) {
if (h[c - 1] - b * i < 0) {
health(c, a * i, b * i);
for (int j = 0; j < i; j++) tmp.push_back(c);
dfs(c + 1, times + i);
health(c, -a * i, -b * i);
for (int j = 0; j < i; j++) tmp.pop_back();
}
}
return;
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", h + i);
}
dfs(2, 0);
printf("%d\n", ans);
for (int i = 0; i < hit.size(); i++) printf("%d ", hit[i]);
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15 + 2;
int n, a, b, h[maxn], ans = 0x7fffffff;
vector<int> hit, tmp;
void health(int c, int a, int b) {
h[c - 1] -= b;
h[c + 1] -= b;
h[c] -= a;
return;
}
void dfs(int c, int times) {
if (times >= ans) return;
if (c == n) {
if (h[n] < 0) {
ans = times;
hit = tmp;
}
return;
}
for (int i = 0;
i <= max(h[c - 1] / b + 1, max(h[c] / a + 1, h[c + 1] / b + 1)); i++) {
if (h[c - 1] - b * i < 0) {
health(c, a * i, b * i);
for (int j = 0; j < i; j++) tmp.push_back(c);
dfs(c + 1, times + i);
health(c, -a * i, -b * i);
for (int j = 0; j < i; j++) tmp.pop_back();
}
}
return;
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", h + i);
}
dfs(2, 0);
printf("%d\n", ans);
for (int i = 0; i < hit.size(); i++) printf("%d ", hit[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
int a[14];
int b[14];
int ans[14];
int x, y;
int mi;
void f(int u, int e, int step) {
int i, tim = 0;
if (a[u - 1] >= 0) {
tim = (a[u - 1] / y) + 1;
}
if (u == e) {
if (a[e] >= 0) {
step += tim + (a[e] / x + 1);
b[e] = a[e] / x + 1 + tim;
} else
step += tim, b[e] = tim;
if (step < mi) {
mi = step;
for (i = 2; i <= e; i++) ans[i] = b[i];
}
return;
}
for (i = tim; i <= 15; i++) {
if (i != tim && a[u] < 0) break;
a[u - 1] -= i * y;
a[u] -= i * x;
a[u + 1] -= i * y;
b[u] = i;
f(u + 1, e, step + i);
a[u - 1] += i * y;
a[u] += i * x;
a[u + 1] += i * y;
}
}
int main() {
int i, j, n;
while (~scanf("%d%d%d", &n, &x, &y)) {
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
int z1 = 0, z2 = 0, step = 0;
while (a[1] >= 0) {
a[1] -= y;
a[2] -= x;
a[3] -= y;
z1++;
}
while (a[n] >= 0) {
a[n - 2] -= y;
a[n - 1] -= x;
a[n] -= y;
z2++;
}
memset(ans, 0, sizeof(ans));
step = z1 + z2;
mi = 999999;
f(2, n - 1, 0);
printf("%d\n", mi + step);
ans[2] += z1;
ans[n - 1] += z2;
bool fir = true;
for (i = 2; i <= n - 1; i++) {
while (ans[i]) {
if (!fir) printf(" ");
fir = false;
printf("%d", i);
ans[i]--;
}
}
printf("\n");
}
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
int a[14];
int b[14];
int ans[14];
int x, y;
int mi;
void f(int u, int e, int step) {
int i, tim = 0;
if (a[u - 1] >= 0) {
tim = (a[u - 1] / y) + 1;
}
if (u == e) {
if (a[e] >= 0) {
step += tim + (a[e] / x + 1);
b[e] = a[e] / x + 1 + tim;
} else
step += tim, b[e] = tim;
if (step < mi) {
mi = step;
for (i = 2; i <= e; i++) ans[i] = b[i];
}
return;
}
for (i = tim; i <= 15; i++) {
if (i != tim && a[u] < 0) break;
a[u - 1] -= i * y;
a[u] -= i * x;
a[u + 1] -= i * y;
b[u] = i;
f(u + 1, e, step + i);
a[u - 1] += i * y;
a[u] += i * x;
a[u + 1] += i * y;
}
}
int main() {
int i, j, n;
while (~scanf("%d%d%d", &n, &x, &y)) {
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
int z1 = 0, z2 = 0, step = 0;
while (a[1] >= 0) {
a[1] -= y;
a[2] -= x;
a[3] -= y;
z1++;
}
while (a[n] >= 0) {
a[n - 2] -= y;
a[n - 1] -= x;
a[n] -= y;
z2++;
}
memset(ans, 0, sizeof(ans));
step = z1 + z2;
mi = 999999;
f(2, n - 1, 0);
printf("%d\n", mi + step);
ans[2] += z1;
ans[n - 1] += z2;
bool fir = true;
for (i = 2; i <= n - 1; i++) {
while (ans[i]) {
if (!fir) printf(" ");
fir = false;
printf("%d", i);
ans[i]--;
}
}
printf("\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int ans = 9999999;
int h[100];
int a, b, n;
vector<int> V;
vector<int> V2;
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[x] < 0) {
V2 = V;
ans = times;
}
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) V.push_back(x);
dfs(x + 1, times + i);
for (int j = 0; j < i; j++) V.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < V2.size(); i++) cout << V2[i] << " ";
cout << endl;
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int ans = 9999999;
int h[100];
int a, b, n;
vector<int> V;
vector<int> V2;
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[x] < 0) {
V2 = V;
ans = times;
}
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) V.push_back(x);
dfs(x + 1, times + i);
for (int j = 0; j < i; j++) V.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < V2.size(); i++) cout << V2[i] << " ";
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[100];
int dp[12][20][20][20];
int pred1[12][20][20][20];
int pred2[12][20][20][20];
int pred3[12][20][20][20];
int pred4[12][20][20][20];
inline void check(int i, int x, int y, int z, int xx, int yy, int zz, int r) {
if (xx) return;
if (dp[i][x][y][z] + r > dp[i + 1][yy][zz][h[i + 2]]) return;
dp[i + 1][yy][zz][h[i + 2]] = dp[i][x][y][z] + r;
pred1[i + 1][yy][zz][h[i + 2]] = x;
pred2[i + 1][yy][zz][h[i + 2]] = y;
pred3[i + 1][yy][zz][h[i + 2]] = z;
pred4[i + 1][yy][zz][h[i + 2]] = r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
++h[i];
}
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= 17; ++j)
for (int k = 0; k <= 17; ++k)
for (int z = 0; z <= 17; ++z) dp[i][j][k][z] = 1e9;
dp[2][h[1]][h[2]][h[3]] = 0;
for (int i = 2; i < n; ++i) {
for (int j = 0; j <= 17; ++j)
for (int k = 0; k <= 17; ++k) {
for (int z = 0; z <= 17; ++z)
if (dp[i][j][k][z] != 1e9) {
for (int zz = 0; zz <= 17; ++zz) {
check(i, j, k, z, max(0, j - zz * b), max(0, k - a * zz),
max(0, z - b * zz), zz);
}
}
}
}
int res = 1e9;
int pos1 = 0, pos2 = 0, pos3 = 0;
for (int i = 0; i <= 17; ++i)
for (int k = 0; k <= 17; ++k) {
for (int z = 0; z <= 17; ++z) {
if (i <= z * a && k <= z * b && res > dp[n][i][k][0] + z) {
res = dp[n][i][k][0] + z;
pos1 = i;
pos2 = k;
pos3 = z;
}
}
}
cout << res << '\n';
vector<int> ans;
for (int j = 1; j <= pos3; ++j) ans.push_back(n - 1);
pos3 = 0;
for (int i = n; i > 0; --i) {
for (int j = 1; j <= pred4[i][pos1][pos2][pos3]; ++j) ans.push_back(i - 1);
int x, y, z;
x = pred1[i][pos1][pos2][pos3];
y = pred2[i][pos1][pos2][pos3];
z = pred3[i][pos1][pos2][pos3];
pos1 = x;
pos2 = y;
pos3 = z;
}
for (int i = ans.size() - 1; i >= 0; --i) cout << ans[i] << " ";
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[100];
int dp[12][20][20][20];
int pred1[12][20][20][20];
int pred2[12][20][20][20];
int pred3[12][20][20][20];
int pred4[12][20][20][20];
inline void check(int i, int x, int y, int z, int xx, int yy, int zz, int r) {
if (xx) return;
if (dp[i][x][y][z] + r > dp[i + 1][yy][zz][h[i + 2]]) return;
dp[i + 1][yy][zz][h[i + 2]] = dp[i][x][y][z] + r;
pred1[i + 1][yy][zz][h[i + 2]] = x;
pred2[i + 1][yy][zz][h[i + 2]] = y;
pred3[i + 1][yy][zz][h[i + 2]] = z;
pred4[i + 1][yy][zz][h[i + 2]] = r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
++h[i];
}
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= 17; ++j)
for (int k = 0; k <= 17; ++k)
for (int z = 0; z <= 17; ++z) dp[i][j][k][z] = 1e9;
dp[2][h[1]][h[2]][h[3]] = 0;
for (int i = 2; i < n; ++i) {
for (int j = 0; j <= 17; ++j)
for (int k = 0; k <= 17; ++k) {
for (int z = 0; z <= 17; ++z)
if (dp[i][j][k][z] != 1e9) {
for (int zz = 0; zz <= 17; ++zz) {
check(i, j, k, z, max(0, j - zz * b), max(0, k - a * zz),
max(0, z - b * zz), zz);
}
}
}
}
int res = 1e9;
int pos1 = 0, pos2 = 0, pos3 = 0;
for (int i = 0; i <= 17; ++i)
for (int k = 0; k <= 17; ++k) {
for (int z = 0; z <= 17; ++z) {
if (i <= z * a && k <= z * b && res > dp[n][i][k][0] + z) {
res = dp[n][i][k][0] + z;
pos1 = i;
pos2 = k;
pos3 = z;
}
}
}
cout << res << '\n';
vector<int> ans;
for (int j = 1; j <= pos3; ++j) ans.push_back(n - 1);
pos3 = 0;
for (int i = n; i > 0; --i) {
for (int j = 1; j <= pred4[i][pos1][pos2][pos3]; ++j) ans.push_back(i - 1);
int x, y, z;
x = pred1[i][pos1][pos2][pos3];
y = pred2[i][pos1][pos2][pos3];
z = pred3[i][pos1][pos2][pos3];
pos1 = x;
pos2 = y;
pos3 = z;
}
for (int i = ans.size() - 1; i >= 0; --i) cout << ans[i] << " ";
}
```
|
#include <bits/stdc++.h>
const int maxn = 15;
const int maxh = 20;
int n, a, b;
int h[maxn];
int g[maxn][maxh][maxh];
const int INF = 233;
int pre[maxh][maxh][maxh];
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; ++i) {
scanf("%d", &h[i]);
++h[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < maxh; ++j) {
for (int k = 0; k < maxh; ++k) {
g[i][j][k] = INF;
}
}
}
g[1][h[1]][h[2]] = 0;
for (int i = 2; i < n; ++i) {
for (int j = 0; j <= h[i - 1]; ++j) {
for (int k = 0; k <= h[i]; ++k) {
if (g[i - 1][j][k] >= INF) continue;
int lb = (j + b - 1) / b;
int ub =
std::max(lb, std::max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int l = lb; l <= ub; ++l) {
int x = std::max(0, k - l * a);
int y = std::max(0, h[i + 1] - l * b);
if (g[i][x][y] > g[i - 1][j][k] + l) {
g[i][x][y] = g[i - 1][j][k] + l;
pre[i][x][y] = (j << 8) | k;
}
}
}
}
}
printf("%d\n", g[n - 1][0][0]);
int x = 0, y = 0, i = n - 1;
while (i > 1) {
int l = pre[i][x][y];
int t = g[i][x][y] - g[i - 1][l >> 8][l & 0xff];
for (int j = 0; j < t; ++j) printf("%d ", i);
x = (l >> 8) & 0xff, y = (l & 0xff);
--i;
}
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
const int maxn = 15;
const int maxh = 20;
int n, a, b;
int h[maxn];
int g[maxn][maxh][maxh];
const int INF = 233;
int pre[maxh][maxh][maxh];
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; ++i) {
scanf("%d", &h[i]);
++h[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < maxh; ++j) {
for (int k = 0; k < maxh; ++k) {
g[i][j][k] = INF;
}
}
}
g[1][h[1]][h[2]] = 0;
for (int i = 2; i < n; ++i) {
for (int j = 0; j <= h[i - 1]; ++j) {
for (int k = 0; k <= h[i]; ++k) {
if (g[i - 1][j][k] >= INF) continue;
int lb = (j + b - 1) / b;
int ub =
std::max(lb, std::max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int l = lb; l <= ub; ++l) {
int x = std::max(0, k - l * a);
int y = std::max(0, h[i + 1] - l * b);
if (g[i][x][y] > g[i - 1][j][k] + l) {
g[i][x][y] = g[i - 1][j][k] + l;
pre[i][x][y] = (j << 8) | k;
}
}
}
}
}
printf("%d\n", g[n - 1][0][0]);
int x = 0, y = 0, i = n - 1;
while (i > 1) {
int l = pre[i][x][y];
int t = g[i][x][y] - g[i - 1][l >> 8][l & 0xff];
for (int j = 0; j < t; ++j) printf("%d ", i);
x = (l >> 8) & 0xff, y = (l & 0xff);
--i;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, x, y, ans;
int a[11], b[11];
short int num(int i) {
int rlt = 0;
while (i) rlt += (i % 9), i /= 9;
return rlt;
}
int main() {
scanf("%d %d %d", &n, &x, &y);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int r1 = a[1] / y + 1, r2 = a[n] / y + 1;
if (n == 3) {
int r = ((r1) > (r2) ? (r1) : (r2));
r = ((a[2] / x + 1) > (r) ? (a[2] / x + 1) : (r));
printf("%d\n", r);
for (int i = 0; i < r; i++) printf("2 ");
puts("");
return 0;
}
ans = r1 + r2;
a[1] -= y * r1, a[2] -= x * r1, a[3] -= y * r1;
a[n] -= y * r2, a[n - 1] -= x * r2, a[n - 2] -= y * r2;
int st = 1, en = n;
while (a[st] < 0) st++;
while (a[en] < 0) en--;
int lim = 1;
for (int i = st; i <= en; i++) lim *= 9;
int bits = lim - 1, mn = 43046721;
for (int i = 0; i < lim; i++) {
int NUM = num(i);
if (NUM >= mn) continue;
int j = i;
for (int k = st; k <= en; k++) b[k] = a[k];
for (int k = st; k <= en; k++) {
int r = j % 9;
j /= 9;
b[k] -= x * r, b[k - 1] -= y * r, b[k + 1] -= y * r;
}
bool fg = 1;
for (int k = st; k <= en; k++)
if (b[k] >= 0) {
fg = 0;
break;
}
if (fg) bits = i, mn = NUM;
}
ans += mn;
printf("%d\n", ans);
for (int i = 0; i < r1; i++) printf("2 ");
for (int i = 0; i < r2; i++) printf("%d ", n - 1);
for (int k = st; k <= en; k++) {
int r = bits % 9;
for (int j = 0; j < r; j++) printf("%d ", k);
bits /= 9;
}
puts("");
}
|
### Prompt
Create a solution in Cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, x, y, ans;
int a[11], b[11];
short int num(int i) {
int rlt = 0;
while (i) rlt += (i % 9), i /= 9;
return rlt;
}
int main() {
scanf("%d %d %d", &n, &x, &y);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int r1 = a[1] / y + 1, r2 = a[n] / y + 1;
if (n == 3) {
int r = ((r1) > (r2) ? (r1) : (r2));
r = ((a[2] / x + 1) > (r) ? (a[2] / x + 1) : (r));
printf("%d\n", r);
for (int i = 0; i < r; i++) printf("2 ");
puts("");
return 0;
}
ans = r1 + r2;
a[1] -= y * r1, a[2] -= x * r1, a[3] -= y * r1;
a[n] -= y * r2, a[n - 1] -= x * r2, a[n - 2] -= y * r2;
int st = 1, en = n;
while (a[st] < 0) st++;
while (a[en] < 0) en--;
int lim = 1;
for (int i = st; i <= en; i++) lim *= 9;
int bits = lim - 1, mn = 43046721;
for (int i = 0; i < lim; i++) {
int NUM = num(i);
if (NUM >= mn) continue;
int j = i;
for (int k = st; k <= en; k++) b[k] = a[k];
for (int k = st; k <= en; k++) {
int r = j % 9;
j /= 9;
b[k] -= x * r, b[k - 1] -= y * r, b[k + 1] -= y * r;
}
bool fg = 1;
for (int k = st; k <= en; k++)
if (b[k] >= 0) {
fg = 0;
break;
}
if (fg) bits = i, mn = NUM;
}
ans += mn;
printf("%d\n", ans);
for (int i = 0; i < r1; i++) printf("2 ");
for (int i = 0; i < r2; i++) printf("%d ", n - 1);
for (int k = st; k <= en; k++) {
int r = bits % 9;
for (int j = 0; j < r; j++) printf("%d ", k);
bits /= 9;
}
puts("");
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int dp[15][20][20], n, a, b;
int X[15][20][20], Y[15][20][20];
int h[20], first;
void output(int dep, int x, int y) {
if (dep == 2) return;
output(dep - 1, X[dep][x][y], Y[dep][x][y]);
for (int i = 0; i < dp[dep][x][y] - dp[dep - 1][X[dep][x][y]][Y[dep][x][y]];
i++) {
if (first)
first = 0;
else
printf(" ");
printf("%d", dep - 1);
}
}
int main() {
while (scanf("%d%d%d", &n, &a, &b) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]), h[i]++;
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 16; j++) {
for (int k = 0; k <= 16; k++) {
dp[i][j][k] = INF;
}
}
}
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == INF) continue;
int from = (j + b - 1) / b;
int to = max(from, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = from; hit <= to; hit++) {
if (dp[i + 1][max(0, k - hit * a)][max(0, h[i + 1] - hit * b)] >
dp[i][j][k] + hit) {
dp[i + 1][max(0, k - hit * a)][max(0, h[i + 1] - hit * b)] =
dp[i][j][k] + hit;
X[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - hit * b)] = j;
Y[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - hit * b)] = k;
}
}
}
}
}
printf("%d\n", dp[n][0][0]);
first = 1;
output(n, 0, 0);
printf("\n");
}
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int dp[15][20][20], n, a, b;
int X[15][20][20], Y[15][20][20];
int h[20], first;
void output(int dep, int x, int y) {
if (dep == 2) return;
output(dep - 1, X[dep][x][y], Y[dep][x][y]);
for (int i = 0; i < dp[dep][x][y] - dp[dep - 1][X[dep][x][y]][Y[dep][x][y]];
i++) {
if (first)
first = 0;
else
printf(" ");
printf("%d", dep - 1);
}
}
int main() {
while (scanf("%d%d%d", &n, &a, &b) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]), h[i]++;
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 16; j++) {
for (int k = 0; k <= 16; k++) {
dp[i][j][k] = INF;
}
}
}
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == INF) continue;
int from = (j + b - 1) / b;
int to = max(from, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = from; hit <= to; hit++) {
if (dp[i + 1][max(0, k - hit * a)][max(0, h[i + 1] - hit * b)] >
dp[i][j][k] + hit) {
dp[i + 1][max(0, k - hit * a)][max(0, h[i + 1] - hit * b)] =
dp[i][j][k] + hit;
X[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - hit * b)] = j;
Y[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - hit * b)] = k;
}
}
}
}
}
printf("%d\n", dp[n][0][0]);
first = 1;
output(n, 0, 0);
printf("\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, p, e;
int h[16];
int s[16 * 16];
int nbs = 0x7fffffff;
int bs[16 * 16];
bool is_ans() {
for (int i = 1; i <= n; i++)
if (h[i] >= 0) {
return false;
}
return true;
}
void dfs(int i) {
if (i >= nbs) {
return;
}
if (is_ans()) {
if (i < nbs) {
nbs = i;
for (int j = 0; j < i; j++) {
bs[j] = s[j];
}
}
return;
}
for (int j = (i > 0 ? s[i - 1] : 2); j < n; j++) {
if (h[j] >= 0 || h[j - 1] >= 0 || h[j + 1] >= 0) {
s[i] = j;
h[j] -= a;
h[j - 1] -= b;
h[j + 1] -= b;
dfs(i + 1);
h[j] += a;
h[j - 1] += b;
h[j + 1] += b;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
while (h[0] > 0) {
p++;
h[0] -= b;
h[1] -= a;
h[2] -= b;
}
while (h[n] > 0) {
e++;
h[n] -= b;
h[n - 1] -= a;
h[n - 2] -= b;
}
dfs(0);
for (int i = 0; i < nbs; i++) {
bs[i + p] = bs[i];
}
for (int i = 0; i < p; i++) {
bs[i] = 2;
}
for (int i = 0; i < e; i++) {
bs[nbs + i] = n - 1;
}
nbs = nbs + p + e;
cout << nbs << endl;
cout << bs[0];
for (int i = 1; i < nbs; i++) {
cout << ' ' << bs[i];
}
cout << endl;
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, p, e;
int h[16];
int s[16 * 16];
int nbs = 0x7fffffff;
int bs[16 * 16];
bool is_ans() {
for (int i = 1; i <= n; i++)
if (h[i] >= 0) {
return false;
}
return true;
}
void dfs(int i) {
if (i >= nbs) {
return;
}
if (is_ans()) {
if (i < nbs) {
nbs = i;
for (int j = 0; j < i; j++) {
bs[j] = s[j];
}
}
return;
}
for (int j = (i > 0 ? s[i - 1] : 2); j < n; j++) {
if (h[j] >= 0 || h[j - 1] >= 0 || h[j + 1] >= 0) {
s[i] = j;
h[j] -= a;
h[j - 1] -= b;
h[j + 1] -= b;
dfs(i + 1);
h[j] += a;
h[j - 1] += b;
h[j + 1] += b;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
while (h[0] > 0) {
p++;
h[0] -= b;
h[1] -= a;
h[2] -= b;
}
while (h[n] > 0) {
e++;
h[n] -= b;
h[n - 1] -= a;
h[n - 2] -= b;
}
dfs(0);
for (int i = 0; i < nbs; i++) {
bs[i + p] = bs[i];
}
for (int i = 0; i < p; i++) {
bs[i] = 2;
}
for (int i = 0; i < e; i++) {
bs[nbs + i] = n - 1;
}
nbs = nbs + p + e;
cout << nbs << endl;
cout << bs[0];
for (int i = 1; i < nbs; i++) {
cout << ' ' << bs[i];
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
const int N = 18;
int h[N];
int f[13][N][N];
std::pair<int, int> opt[13][N][N];
inline void chmin(int &a, const int &b) { (a > b) && (a = b); }
void print(int i, int j, int k) {
if (i == 1) return;
for (int _ = 1; _ <= k; ++_) {
printf("%d ", i);
}
print(i - 1, opt[i][j][k].first, opt[i][j][k].second);
}
int main() {
memset(f, 63, sizeof(f));
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]), ++h[i];
f[1][h[1]][0] = 0;
for (int i = 2; i < n; ++i) {
for (int j = 0; j <= h[i]; ++j) {
for (int k = 0; k <= 16; ++k) {
for (int tmp = 0; tmp <= h[i - 1]; ++tmp) {
for (int t = 0; t <= 16; ++t) {
if (j) {
if (k * a + j + t * b == h[i] && k * b >= tmp) {
chmin(f[i][j][k], f[i - 1][tmp][t] + k);
if (f[i][j][k] == f[i - 1][tmp][t] + k) {
opt[i][j][k] = std::make_pair(tmp, t);
}
}
} else {
if (k * a + t * b >= h[i] && k * b >= tmp) {
chmin(f[i][j][k], f[i - 1][tmp][t] + k);
if (f[i][j][k] == f[i - 1][tmp][t] + k) {
opt[i][j][k] = std::make_pair(tmp, t);
}
}
}
}
}
}
}
}
int ans = 0x3f3f3f3f;
int pos = 0;
for (int i = 0; i <= 16; ++i) {
if (i * b >= h[n]) {
chmin(ans, f[n - 1][0][i]);
if (ans == f[n - 1][0][i]) {
pos = i;
}
}
}
printf("%d\n", ans);
print(n - 1, 0, pos);
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
const int N = 18;
int h[N];
int f[13][N][N];
std::pair<int, int> opt[13][N][N];
inline void chmin(int &a, const int &b) { (a > b) && (a = b); }
void print(int i, int j, int k) {
if (i == 1) return;
for (int _ = 1; _ <= k; ++_) {
printf("%d ", i);
}
print(i - 1, opt[i][j][k].first, opt[i][j][k].second);
}
int main() {
memset(f, 63, sizeof(f));
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]), ++h[i];
f[1][h[1]][0] = 0;
for (int i = 2; i < n; ++i) {
for (int j = 0; j <= h[i]; ++j) {
for (int k = 0; k <= 16; ++k) {
for (int tmp = 0; tmp <= h[i - 1]; ++tmp) {
for (int t = 0; t <= 16; ++t) {
if (j) {
if (k * a + j + t * b == h[i] && k * b >= tmp) {
chmin(f[i][j][k], f[i - 1][tmp][t] + k);
if (f[i][j][k] == f[i - 1][tmp][t] + k) {
opt[i][j][k] = std::make_pair(tmp, t);
}
}
} else {
if (k * a + t * b >= h[i] && k * b >= tmp) {
chmin(f[i][j][k], f[i - 1][tmp][t] + k);
if (f[i][j][k] == f[i - 1][tmp][t] + k) {
opt[i][j][k] = std::make_pair(tmp, t);
}
}
}
}
}
}
}
}
int ans = 0x3f3f3f3f;
int pos = 0;
for (int i = 0; i <= 16; ++i) {
if (i * b >= h[n]) {
chmin(ans, f[n - 1][0][i]);
if (ans == f[n - 1][0][i]) {
pos = i;
}
}
}
printf("%d\n", ans);
print(n - 1, 0, pos);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFL = 10000000000000000LL;
const double eps = 1e-9;
const double PI = acos(-1.0);
int dp[15][20][20][20];
int v[15];
int n, a, b;
struct Node {
int i, j, k, l;
bool operator==(const Node& tmp) {
return i == tmp.i && j == tmp.j && k == tmp.k && l == tmp.l;
}
Node(int i, int j, int k, int l) : i(i), j(j), k(k), l(l) {}
Node() {}
} pre[15][20][20][20];
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
v[i]++;
}
memset(dp, 0x3f, sizeof(dp));
int INF = dp[0][0][0][0];
dp[1][v[0]][v[1]][v[2]] = 0;
for (int i = 1; i < n - 1; i++) {
for (int j = v[i - 1]; j >= 0; j--) {
for (int k = v[i]; k >= 0; k--) {
for (int l = v[i + 1]; l >= 0; l--) {
if (dp[i][j][k][l] >= INF) continue;
if (j == 0 && dp[i + 1][k][l][v[i + 2]] > dp[i][j][k][l]) {
dp[i + 1][k][l][v[i + 2]] = dp[i][j][k][l];
pre[i + 1][k][l][v[i + 2]] = pre[i][j][k][l];
}
int nj = max(0, j - b);
int nk = max(0, k - a);
int nl = max(0, l - b);
if (dp[i][nj][nk][nl] > dp[i][j][k][l] + 1) {
dp[i][nj][nk][nl] = dp[i][j][k][l] + 1;
pre[i][nj][nk][nl] = Node(i, j, k, l);
}
if (nj == 0 && dp[i + 1][nk][nl][v[i + 2]] > dp[i][j][k][l] + 1) {
dp[i + 1][nk][nl][v[i + 2]] = dp[i][j][k][l] + 1;
pre[i + 1][nk][nl][v[i + 2]] = Node(i, j, k, l);
}
}
}
}
}
printf("%d\n", dp[n - 2][0][0][0]);
Node tmp = pre[n - 2][0][0][0];
while (1) {
printf("%d ", tmp.i + 1);
if (tmp == Node(1, v[0], v[1], v[2])) break;
tmp = pre[tmp.i][tmp.j][tmp.k][tmp.l];
}
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFL = 10000000000000000LL;
const double eps = 1e-9;
const double PI = acos(-1.0);
int dp[15][20][20][20];
int v[15];
int n, a, b;
struct Node {
int i, j, k, l;
bool operator==(const Node& tmp) {
return i == tmp.i && j == tmp.j && k == tmp.k && l == tmp.l;
}
Node(int i, int j, int k, int l) : i(i), j(j), k(k), l(l) {}
Node() {}
} pre[15][20][20][20];
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
v[i]++;
}
memset(dp, 0x3f, sizeof(dp));
int INF = dp[0][0][0][0];
dp[1][v[0]][v[1]][v[2]] = 0;
for (int i = 1; i < n - 1; i++) {
for (int j = v[i - 1]; j >= 0; j--) {
for (int k = v[i]; k >= 0; k--) {
for (int l = v[i + 1]; l >= 0; l--) {
if (dp[i][j][k][l] >= INF) continue;
if (j == 0 && dp[i + 1][k][l][v[i + 2]] > dp[i][j][k][l]) {
dp[i + 1][k][l][v[i + 2]] = dp[i][j][k][l];
pre[i + 1][k][l][v[i + 2]] = pre[i][j][k][l];
}
int nj = max(0, j - b);
int nk = max(0, k - a);
int nl = max(0, l - b);
if (dp[i][nj][nk][nl] > dp[i][j][k][l] + 1) {
dp[i][nj][nk][nl] = dp[i][j][k][l] + 1;
pre[i][nj][nk][nl] = Node(i, j, k, l);
}
if (nj == 0 && dp[i + 1][nk][nl][v[i + 2]] > dp[i][j][k][l] + 1) {
dp[i + 1][nk][nl][v[i + 2]] = dp[i][j][k][l] + 1;
pre[i + 1][nk][nl][v[i + 2]] = Node(i, j, k, l);
}
}
}
}
}
printf("%d\n", dp[n - 2][0][0][0]);
Node tmp = pre[n - 2][0][0][0];
while (1) {
printf("%d ", tmp.i + 1);
if (tmp == Node(1, v[0], v[1], v[2])) break;
tmp = pre[tmp.i][tmp.j][tmp.k][tmp.l];
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int floord(int x, int y) {
if (x < 0) return 0;
return (x / y + (x % y ? 1 : 0));
}
bool cmpless(std::pair<int, int> p1, std::pair<int, int> p2) {
return (p1.first < p2.first ||
(p1.first == p2.first && (p1.second > p2.second)));
}
std::vector<int> oo(std::vector<int>& h) {
std::vector<std::vector<std::pair<int, int> > > v(n);
std::vector<std::vector<std::vector<int> > > P(n);
for (int i = 0; i < n; ++i) {
v[i].resize(h[i] + 1, make_pair(1000000, 1000000));
P[i].resize(h[i] + 1);
}
v[0][h[0]] = make_pair(0, 0);
P[0][h[0]].push_back(0);
for (int i = 1; i < n - 2; ++i) {
for (int j = 0; j <= h[i]; ++j) {
for (int k = 0; k <= h[i - 1]; ++k) {
int t = v[i - 1][k].first;
int at = v[i - 1][k].second;
int a1 = max(floord(k, b), floord(h[i] - at * b - j, a));
if (cmpless(make_pair(t + a1, a1), v[i][j])) {
v[i][j] = make_pair(t + a1, a1);
P[i][j] = P[i - 1][k];
P[i][j].push_back(a1);
}
}
}
}
int prin;
for (int i = 0; i <= h[n - 3]; ++i) {
int t = v[n - 3][i].first;
int at = v[n - 3][i].second;
int prev = i;
int curr = h[n - 2] - b * at;
int ahea = h[n - 1];
int a1 = max(max(floord(prev, b), floord(curr, a)), floord(ahea, b));
t += a1;
if (cmpless(make_pair(t, a1), v[n - 2][0])) {
v[n - 2][0] = make_pair(t, a1);
prin = i;
P[n - 2][0] = P[n - 3][i];
P[n - 2][0].push_back(a1);
}
}
return P[n - 2][0];
}
std::vector<int> oo1(std::vector<int>& h) {
std::vector<std::vector<std::pair<int, int> > > v(n);
std::vector<std::vector<std::vector<int> > > P(n);
for (int i = 0; i < n; ++i) {
v[i].resize(h[i] + 1, make_pair(1000000, 1000000));
P[i].resize(h[i] + 1);
}
v[0][h[0]] = make_pair(0, 0);
P[0][h[0]].push_back(0);
for (int i = 1; i < n - 2; ++i) {
for (int j = 0; j <= h[i]; ++j) {
for (int k = 0; k <= h[i - 1]; ++k) {
int t = v[i - 1][k].first;
int at = v[i - 1][k].second;
int a1 = max(floord(k, b), floord(h[i] - at * b - j, a));
if (make_pair(t + a1, a1) < v[i][j]) {
v[i][j] = make_pair(t + a1, a1);
P[i][j] = P[i - 1][k];
P[i][j].push_back(a1);
}
}
}
}
int prin;
for (int i = 0; i <= h[n - 3]; ++i) {
int t = v[n - 3][i].first;
int at = v[n - 3][i].second;
int prev = i;
int curr = h[n - 2] - b * at;
int ahea = h[n - 1];
int a1 = max(max(floord(prev, b), floord(curr, a)), floord(ahea, b));
t += a1;
if (make_pair(t, a1) < v[n - 2][0]) {
v[n - 2][0] = make_pair(t, a1);
prin = i;
P[n - 2][0] = P[n - 3][i];
P[n - 2][0].push_back(a1);
}
}
return P[n - 2][0];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> a >> b;
std::vector<int> h(n);
for (int i = 0; i < n; ++i) {
cin >> h[i];
h[i]++;
}
std::vector<int> v1 = oo(h);
std::vector<int> v2 = oo1(h);
int t1 = 0;
for (int i = 0; i < n - 1; ++i) t1 += v1[i];
int t2 = 0;
for (int i = 0; i < n - 1; ++i) t2 += v2[i];
if (t2 < t1) {
v1 = v2;
t1 = t2;
}
cout << t1 << "\n";
for (int i = 0; i < n - 1; ++i)
for (int j = 0; j < v1[i]; ++j) cout << i + 1 << " ";
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int floord(int x, int y) {
if (x < 0) return 0;
return (x / y + (x % y ? 1 : 0));
}
bool cmpless(std::pair<int, int> p1, std::pair<int, int> p2) {
return (p1.first < p2.first ||
(p1.first == p2.first && (p1.second > p2.second)));
}
std::vector<int> oo(std::vector<int>& h) {
std::vector<std::vector<std::pair<int, int> > > v(n);
std::vector<std::vector<std::vector<int> > > P(n);
for (int i = 0; i < n; ++i) {
v[i].resize(h[i] + 1, make_pair(1000000, 1000000));
P[i].resize(h[i] + 1);
}
v[0][h[0]] = make_pair(0, 0);
P[0][h[0]].push_back(0);
for (int i = 1; i < n - 2; ++i) {
for (int j = 0; j <= h[i]; ++j) {
for (int k = 0; k <= h[i - 1]; ++k) {
int t = v[i - 1][k].first;
int at = v[i - 1][k].second;
int a1 = max(floord(k, b), floord(h[i] - at * b - j, a));
if (cmpless(make_pair(t + a1, a1), v[i][j])) {
v[i][j] = make_pair(t + a1, a1);
P[i][j] = P[i - 1][k];
P[i][j].push_back(a1);
}
}
}
}
int prin;
for (int i = 0; i <= h[n - 3]; ++i) {
int t = v[n - 3][i].first;
int at = v[n - 3][i].second;
int prev = i;
int curr = h[n - 2] - b * at;
int ahea = h[n - 1];
int a1 = max(max(floord(prev, b), floord(curr, a)), floord(ahea, b));
t += a1;
if (cmpless(make_pair(t, a1), v[n - 2][0])) {
v[n - 2][0] = make_pair(t, a1);
prin = i;
P[n - 2][0] = P[n - 3][i];
P[n - 2][0].push_back(a1);
}
}
return P[n - 2][0];
}
std::vector<int> oo1(std::vector<int>& h) {
std::vector<std::vector<std::pair<int, int> > > v(n);
std::vector<std::vector<std::vector<int> > > P(n);
for (int i = 0; i < n; ++i) {
v[i].resize(h[i] + 1, make_pair(1000000, 1000000));
P[i].resize(h[i] + 1);
}
v[0][h[0]] = make_pair(0, 0);
P[0][h[0]].push_back(0);
for (int i = 1; i < n - 2; ++i) {
for (int j = 0; j <= h[i]; ++j) {
for (int k = 0; k <= h[i - 1]; ++k) {
int t = v[i - 1][k].first;
int at = v[i - 1][k].second;
int a1 = max(floord(k, b), floord(h[i] - at * b - j, a));
if (make_pair(t + a1, a1) < v[i][j]) {
v[i][j] = make_pair(t + a1, a1);
P[i][j] = P[i - 1][k];
P[i][j].push_back(a1);
}
}
}
}
int prin;
for (int i = 0; i <= h[n - 3]; ++i) {
int t = v[n - 3][i].first;
int at = v[n - 3][i].second;
int prev = i;
int curr = h[n - 2] - b * at;
int ahea = h[n - 1];
int a1 = max(max(floord(prev, b), floord(curr, a)), floord(ahea, b));
t += a1;
if (make_pair(t, a1) < v[n - 2][0]) {
v[n - 2][0] = make_pair(t, a1);
prin = i;
P[n - 2][0] = P[n - 3][i];
P[n - 2][0].push_back(a1);
}
}
return P[n - 2][0];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> a >> b;
std::vector<int> h(n);
for (int i = 0; i < n; ++i) {
cin >> h[i];
h[i]++;
}
std::vector<int> v1 = oo(h);
std::vector<int> v2 = oo1(h);
int t1 = 0;
for (int i = 0; i < n - 1; ++i) t1 += v1[i];
int t2 = 0;
for (int i = 0; i < n - 1; ++i) t2 += v2[i];
if (t2 < t1) {
v1 = v2;
t1 = t2;
}
cout << t1 << "\n";
for (int i = 0; i < n - 1; ++i)
for (int j = 0; j < v1[i]; ++j) cout << i + 1 << " ";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int dp[15][20][20], n, a, b, h[20];
int X[15][20][20], Y[15][20][20];
void output(int dep, int x, int y) {
if (dep == 2) return;
output(dep - 1, X[dep][x][y], Y[dep][x][y]);
for (int i = 0; i < dp[dep][x][y] - dp[dep - 1][X[dep][x][y]][Y[dep][x][y]];
i++)
printf("%d ", dep - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 16; j++)
for (int k = 0; k <= 16; k++) dp[i][j][k] = 99999999;
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == 99999999) continue;
int from = (j + b - 1) / b;
int to = max(from, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = from; hit <= to; hit++) {
if (dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] >
dp[i][j][k] + hit) {
dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] =
dp[i][j][k] + hit;
X[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = j;
Y[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = k;
}
}
}
}
}
printf("%d\n", dp[n][0][0]);
output(n, 0, 0);
puts("");
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[15][20][20], n, a, b, h[20];
int X[15][20][20], Y[15][20][20];
void output(int dep, int x, int y) {
if (dep == 2) return;
output(dep - 1, X[dep][x][y], Y[dep][x][y]);
for (int i = 0; i < dp[dep][x][y] - dp[dep - 1][X[dep][x][y]][Y[dep][x][y]];
i++)
printf("%d ", dep - 1);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i]++;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 16; j++)
for (int k = 0; k <= 16; k++) dp[i][j][k] = 99999999;
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == 99999999) continue;
int from = (j + b - 1) / b;
int to = max(from, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int hit = from; hit <= to; hit++) {
if (dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] >
dp[i][j][k] + hit) {
dp[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] =
dp[i][j][k] + hit;
X[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = j;
Y[i + 1][max(0, k - a * hit)][max(0, h[i + 1] - b * hit)] = k;
}
}
}
}
}
printf("%d\n", dp[n][0][0]);
output(n, 0, 0);
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 10;
int anum = 1000000000;
int cnt;
int n;
int da;
int db;
int a[N];
int ans[N];
int fang[N];
void ri() {
int i;
cin >> n >> da >> db;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) a[i]++;
}
bool ok() {
int i;
for (i = 0; i < n; i++)
if (a[i] > 0) return false;
return true;
}
void search(int deep) {
int i;
if (deep == n - 1) {
if (ok()) {
if (cnt < anum) {
anum = cnt;
for (i = 0; i < cnt; i++) ans[i] = fang[i];
}
}
return;
}
if (cnt > anum) return;
if (a[deep - 1] <= 0) search(deep + 1);
if (a[deep - 1] > 0 || a[deep] > 0 || a[deep + 1] > 0) {
a[deep - 1] -= db;
a[deep] -= da;
a[deep + 1] -= db;
fang[cnt++] = deep;
search(deep);
cnt--;
a[deep - 1] += db;
a[deep] += da;
a[deep + 1] += db;
}
}
void print() {
int i;
cout << anum << "\n";
for (i = 0; i < anum; i++) cout << ans[i] + 1 << " ";
cout << "\n";
}
int main() {
ri();
search(1);
print();
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 10;
int anum = 1000000000;
int cnt;
int n;
int da;
int db;
int a[N];
int ans[N];
int fang[N];
void ri() {
int i;
cin >> n >> da >> db;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) a[i]++;
}
bool ok() {
int i;
for (i = 0; i < n; i++)
if (a[i] > 0) return false;
return true;
}
void search(int deep) {
int i;
if (deep == n - 1) {
if (ok()) {
if (cnt < anum) {
anum = cnt;
for (i = 0; i < cnt; i++) ans[i] = fang[i];
}
}
return;
}
if (cnt > anum) return;
if (a[deep - 1] <= 0) search(deep + 1);
if (a[deep - 1] > 0 || a[deep] > 0 || a[deep + 1] > 0) {
a[deep - 1] -= db;
a[deep] -= da;
a[deep + 1] -= db;
fang[cnt++] = deep;
search(deep);
cnt--;
a[deep - 1] += db;
a[deep] += da;
a[deep + 1] += db;
}
}
void print() {
int i;
cout << anum << "\n";
for (i = 0; i < anum; i++) cout << ans[i] + 1 << " ";
cout << "\n";
}
int main() {
ri();
search(1);
print();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 12;
const int H = 17;
int n, a, b;
int h[N];
int d[N][H][H];
int p[N][H][H];
void solve() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
memset(d, 0x7f, sizeof d);
for (int i = 0; i < H; i++)
if (b * i > h[1]) d[2][i][0] = i;
for (int i = 3; i < n; i++)
for (int l = 0; l < H; l++)
for (int k = 0; k < H; k++)
for (int j = 0; j < H; j++)
if (a * k + b * (j + l) > h[i - 1]) {
if (d[i][j][k] > d[i - 1][k][l] + j) {
d[i][j][k] = d[i - 1][k][l] + j;
p[i][j][k] = l;
}
}
int ans = INT_MAX;
int J, K;
for (int j = 0; j < H; j++)
for (int k = 0; k < H; k++)
if (b * j > h[n]) {
if (ans > d[n - 1][j][k]) {
ans = d[n - 1][j][k];
J = j;
K = k;
}
}
printf("%d\n", ans);
int c = n - 1;
while (c > 1) {
for (int i = 0; i < J; i++) printf("%d ", c);
int pj = K;
int pk = p[c][J][K];
J = pj, K = pk;
c--;
}
}
int main(void) { solve(); }
|
### Prompt
In CPP, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 12;
const int H = 17;
int n, a, b;
int h[N];
int d[N][H][H];
int p[N][H][H];
void solve() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
memset(d, 0x7f, sizeof d);
for (int i = 0; i < H; i++)
if (b * i > h[1]) d[2][i][0] = i;
for (int i = 3; i < n; i++)
for (int l = 0; l < H; l++)
for (int k = 0; k < H; k++)
for (int j = 0; j < H; j++)
if (a * k + b * (j + l) > h[i - 1]) {
if (d[i][j][k] > d[i - 1][k][l] + j) {
d[i][j][k] = d[i - 1][k][l] + j;
p[i][j][k] = l;
}
}
int ans = INT_MAX;
int J, K;
for (int j = 0; j < H; j++)
for (int k = 0; k < H; k++)
if (b * j > h[n]) {
if (ans > d[n - 1][j][k]) {
ans = d[n - 1][j][k];
J = j;
K = k;
}
}
printf("%d\n", ans);
int c = n - 1;
while (c > 1) {
for (int i = 0; i < J; i++) printf("%d ", c);
int pj = K;
int pk = p[c][J][K];
J = pj, K = pk;
c--;
}
}
int main(void) { solve(); }
```
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 15;
int n, a, b;
int h[MAXN];
vector<int> ans;
vector<int> temp_ans;
vector<int> before;
void solve(int pos, int prev_health, int next_damage) {
if (pos >= n) {
if (h[pos] <= next_damage &&
(temp_ans.size() < ans.size() || ans.size() == 0)) {
ans = temp_ans;
}
return;
}
for (int i = 0;; i++) {
if (i != 0) {
temp_ans.push_back(pos);
}
if (prev_health - i * b <= 0) {
solve(pos + 1, h[pos] - next_damage - i * a, i * b);
if (h[pos] - next_damage - i * a <= 0) {
break;
}
}
}
while (temp_ans.size() > 0 && temp_ans.back() == pos) {
temp_ans.pop_back();
}
return;
}
int main(void) {
scanf(" %d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf(" %d", &h[i]);
h[i]++;
}
while (h[1] > 0) {
h[3] -= b;
h[2] -= a;
h[1] -= b;
before.push_back(2);
}
while (h[n] > 0) {
h[n - 2] -= b;
h[n - 1] -= a;
h[n] -= b;
before.push_back(n - 1);
}
solve(2, h[1], 0);
while (before.size() > 0) {
ans.push_back(before.back());
before.pop_back();
}
printf("%d\n", (int)ans.size());
for (int i = 0; i < (int)ans.size(); i++) {
if (i != 0) {
printf(" ");
}
printf("%d", ans[i]);
}
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 15;
int n, a, b;
int h[MAXN];
vector<int> ans;
vector<int> temp_ans;
vector<int> before;
void solve(int pos, int prev_health, int next_damage) {
if (pos >= n) {
if (h[pos] <= next_damage &&
(temp_ans.size() < ans.size() || ans.size() == 0)) {
ans = temp_ans;
}
return;
}
for (int i = 0;; i++) {
if (i != 0) {
temp_ans.push_back(pos);
}
if (prev_health - i * b <= 0) {
solve(pos + 1, h[pos] - next_damage - i * a, i * b);
if (h[pos] - next_damage - i * a <= 0) {
break;
}
}
}
while (temp_ans.size() > 0 && temp_ans.back() == pos) {
temp_ans.pop_back();
}
return;
}
int main(void) {
scanf(" %d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf(" %d", &h[i]);
h[i]++;
}
while (h[1] > 0) {
h[3] -= b;
h[2] -= a;
h[1] -= b;
before.push_back(2);
}
while (h[n] > 0) {
h[n - 2] -= b;
h[n - 1] -= a;
h[n] -= b;
before.push_back(n - 1);
}
solve(2, h[1], 0);
while (before.size() > 0) {
ans.push_back(before.back());
before.pop_back();
}
printf("%d\n", (int)ans.size());
for (int i = 0; i < (int)ans.size(); i++) {
if (i != 0) {
printf(" ");
}
printf("%d", ans[i]);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h[15], dp[15][20][20], pre1[15][20][20], pre2[15][20][20], n, a, b;
void dfs(int nn, int jj, int kk) {
if (nn == 1) return;
dfs(nn - 1, pre1[nn][jj][kk], pre2[nn][jj][kk]);
int tmp = dp[nn][jj][kk] - dp[nn - 1][pre1[nn][jj][kk]][pre2[nn][jj][kk]];
while (tmp--) printf("%d ", nn);
}
int main(int argc, char *argv[]) {
int mins, maxs, tmp1, tmp2;
while (~scanf("%d%d%d", &n, &a, &b)) {
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j <= 16; j++) {
for (int k = 0; k <= 16; k++) {
dp[i][j][k] = 1000000005;
}
}
}
dp[1][h[0]][h[1]] = 0;
for (int i = 1; i < (n - 1); i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == 1000000005) continue;
mins = (j + b - 1) / b;
tmp1 = (k + a - 1) / a;
tmp2 = (h[i + 1] + b - 1) / b;
maxs = max(mins, max(tmp1, tmp2));
for (int l = mins; l <= maxs; l++) {
if (dp[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] >
dp[i][j][k] + l) {
dp[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] =
dp[i][j][k] + l;
pre1[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] = j;
pre2[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] = k;
}
}
}
}
}
printf("%d\n", dp[n - 1][0][0]);
dfs(n - 1, 0, 0);
printf("\n");
}
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h[15], dp[15][20][20], pre1[15][20][20], pre2[15][20][20], n, a, b;
void dfs(int nn, int jj, int kk) {
if (nn == 1) return;
dfs(nn - 1, pre1[nn][jj][kk], pre2[nn][jj][kk]);
int tmp = dp[nn][jj][kk] - dp[nn - 1][pre1[nn][jj][kk]][pre2[nn][jj][kk]];
while (tmp--) printf("%d ", nn);
}
int main(int argc, char *argv[]) {
int mins, maxs, tmp1, tmp2;
while (~scanf("%d%d%d", &n, &a, &b)) {
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
for (int i = 1; i < n; i++) {
for (int j = 0; j <= 16; j++) {
for (int k = 0; k <= 16; k++) {
dp[i][j][k] = 1000000005;
}
}
}
dp[1][h[0]][h[1]] = 0;
for (int i = 1; i < (n - 1); i++) {
for (int j = 0; j <= h[i - 1]; j++) {
for (int k = 0; k <= h[i]; k++) {
if (dp[i][j][k] == 1000000005) continue;
mins = (j + b - 1) / b;
tmp1 = (k + a - 1) / a;
tmp2 = (h[i + 1] + b - 1) / b;
maxs = max(mins, max(tmp1, tmp2));
for (int l = mins; l <= maxs; l++) {
if (dp[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] >
dp[i][j][k] + l) {
dp[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] =
dp[i][j][k] + l;
pre1[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] = j;
pre2[i + 1][max(k - l * a, 0)][max(h[i + 1] - l * b, 0)] = k;
}
}
}
}
}
printf("%d\n", dp[n - 1][0][0]);
dfs(n - 1, 0, 0);
printf("\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int maxWord, ns, a, b, mv;
int health[20], dp[11][20][20][20][11], mov[200];
int rec(int id, int v1, int v2, int v3, int kill) {
if (kill == ns) return dp[id][v1][v2][v3][kill] = 0;
if (id >= ns - 1) return 123456;
if (dp[id][v1][v2][v3][kill] != -1) return dp[id][v1][v2][v3][kill];
int an1 = 12345, an2 = 12345, k = 0, a1 = 17, a2 = 17, a3 = 17;
if (v1 != 17 || v2 != 17 || v3 != 17) {
if (v2 != 17) {
a2 = v2 - a;
if (a2 < 0) {
a2 = 17;
k++;
}
}
if (v1 != 17) {
a1 = v1 - b;
if (a1 < 0) {
a1 = 17;
k++;
}
}
if (v3 != 17) {
a3 = v3 - b;
if (a3 < 0) {
a3 = 17;
k++;
}
}
an1 = 1 + rec(id, a1, a2, a3, kill + k);
}
an2 = rec(id + 1, v2, v3, health[id + 2], kill);
return dp[id][v1][v2][v3][kill] = min(an1, an2);
}
void call(int id, int v1, int v2, int v3, int kill, int d) {
if (kill == ns) return;
if (id >= ns - 1) return;
int an1 = 12345, an2 = 12345, k = 0, a1 = 17, a2 = 17, a3 = 17, f = 0;
if (v1 != 17 || v2 != 17 || v3 != 17) {
if (v2 != 17) {
a2 = v2 - a;
if (a2 < 0) {
a2 = 17;
k++;
}
}
if (v1 != 17) {
a1 = v1 - b;
if (a1 < 0) {
a1 = 17;
k++;
}
}
if (v3 != 17) {
a3 = v3 - b;
if (a3 < 0) {
a3 = 17;
k++;
}
}
an1 = 1 + dp[id][a1][a2][a3][kill + k];
f = 1;
}
an2 = dp[id + 1][v2][v3][health[id + 2]][kill];
if (f) {
if (an1 == d) {
cout << id + 1 << " ";
call(id, a1, a2, a3, kill + k, d - 1);
} else {
call(id + 1, v2, v3, health[id + 2], kill, d);
}
} else {
call(id + 1, v2, v3, health[id + 2], kill, d);
}
return;
}
int main() {
int i, j, kase = 1, k, l, m, ans;
scanf("%d%d%d", &ns, &a, &b);
for (i = 0; i < ns; i++) scanf("%d", &health[i]);
memset(dp, -1, sizeof(dp));
ans = rec(1, health[0], health[1], health[2], 0);
cout << ans << endl;
call(1, health[0], health[1], health[2], 0, ans);
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int maxWord, ns, a, b, mv;
int health[20], dp[11][20][20][20][11], mov[200];
int rec(int id, int v1, int v2, int v3, int kill) {
if (kill == ns) return dp[id][v1][v2][v3][kill] = 0;
if (id >= ns - 1) return 123456;
if (dp[id][v1][v2][v3][kill] != -1) return dp[id][v1][v2][v3][kill];
int an1 = 12345, an2 = 12345, k = 0, a1 = 17, a2 = 17, a3 = 17;
if (v1 != 17 || v2 != 17 || v3 != 17) {
if (v2 != 17) {
a2 = v2 - a;
if (a2 < 0) {
a2 = 17;
k++;
}
}
if (v1 != 17) {
a1 = v1 - b;
if (a1 < 0) {
a1 = 17;
k++;
}
}
if (v3 != 17) {
a3 = v3 - b;
if (a3 < 0) {
a3 = 17;
k++;
}
}
an1 = 1 + rec(id, a1, a2, a3, kill + k);
}
an2 = rec(id + 1, v2, v3, health[id + 2], kill);
return dp[id][v1][v2][v3][kill] = min(an1, an2);
}
void call(int id, int v1, int v2, int v3, int kill, int d) {
if (kill == ns) return;
if (id >= ns - 1) return;
int an1 = 12345, an2 = 12345, k = 0, a1 = 17, a2 = 17, a3 = 17, f = 0;
if (v1 != 17 || v2 != 17 || v3 != 17) {
if (v2 != 17) {
a2 = v2 - a;
if (a2 < 0) {
a2 = 17;
k++;
}
}
if (v1 != 17) {
a1 = v1 - b;
if (a1 < 0) {
a1 = 17;
k++;
}
}
if (v3 != 17) {
a3 = v3 - b;
if (a3 < 0) {
a3 = 17;
k++;
}
}
an1 = 1 + dp[id][a1][a2][a3][kill + k];
f = 1;
}
an2 = dp[id + 1][v2][v3][health[id + 2]][kill];
if (f) {
if (an1 == d) {
cout << id + 1 << " ";
call(id, a1, a2, a3, kill + k, d - 1);
} else {
call(id + 1, v2, v3, health[id + 2], kill, d);
}
} else {
call(id + 1, v2, v3, health[id + 2], kill, d);
}
return;
}
int main() {
int i, j, kase = 1, k, l, m, ans;
scanf("%d%d%d", &ns, &a, &b);
for (i = 0; i < ns; i++) scanf("%d", &health[i]);
memset(dp, -1, sizeof(dp));
ans = rec(1, health[0], health[1], health[2], 0);
cout << ans << endl;
call(1, health[0], health[1], health[2], 0, ans);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int dp[11][17][17][17], h[11];
vector<int> v[11][17][17][17];
struct p {
int t, x, y, z;
};
int main(void) {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]), h[i]++;
memset(dp, 0x3f, sizeof(dp));
dp[2][h[1]][h[2]][h[3]] = 0;
deque<p> q;
q.push_back({2, h[1], h[2], h[3]});
while (!q.empty()) {
p u = q.front();
q.pop_front();
p v1 = {u.t, max(0, u.x - b), max(0, u.y - a), max(0, u.z - b)};
int du = dp[u.t][u.x][u.y][u.z];
int& dv1 = dp[v1.t][v1.x][v1.y][v1.z];
if (dv1 > du + 1)
dv1 = du + 1, q.push_back(v1),
(v[v1.t][v1.x][v1.y][v1.z] = v[u.t][u.x][u.y][u.z]).push_back(u.t);
if (u.t + 1 >= n || u.x > 0) continue;
p v2 = {u.t + 1, u.y, u.z, h[u.t + 2]};
int& dv2 = dp[v2.t][v2.x][v2.y][v2.z];
if (dv2 > du)
dv2 = du, q.push_front(v2),
(v[v2.t][v2.x][v2.y][v2.z] = v[u.t][u.x][u.y][u.z]);
}
printf("%d\n", dp[n - 1][0][0][0]);
for (int i : v[n - 1][0][0][0]) printf("%d%c", i, ' ');
for (int i : v[n - 1][0][0][0]) h[i] -= a, h[i - 1] -= b, h[i + 1] -= b;
for (int i = 1; i <= n; ++i) assert(h[i] <= 0);
printf("\n");
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[11][17][17][17], h[11];
vector<int> v[11][17][17][17];
struct p {
int t, x, y, z;
};
int main(void) {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]), h[i]++;
memset(dp, 0x3f, sizeof(dp));
dp[2][h[1]][h[2]][h[3]] = 0;
deque<p> q;
q.push_back({2, h[1], h[2], h[3]});
while (!q.empty()) {
p u = q.front();
q.pop_front();
p v1 = {u.t, max(0, u.x - b), max(0, u.y - a), max(0, u.z - b)};
int du = dp[u.t][u.x][u.y][u.z];
int& dv1 = dp[v1.t][v1.x][v1.y][v1.z];
if (dv1 > du + 1)
dv1 = du + 1, q.push_back(v1),
(v[v1.t][v1.x][v1.y][v1.z] = v[u.t][u.x][u.y][u.z]).push_back(u.t);
if (u.t + 1 >= n || u.x > 0) continue;
p v2 = {u.t + 1, u.y, u.z, h[u.t + 2]};
int& dv2 = dp[v2.t][v2.x][v2.y][v2.z];
if (dv2 > du)
dv2 = du, q.push_front(v2),
(v[v2.t][v2.x][v2.y][v2.z] = v[u.t][u.x][u.y][u.z]);
}
printf("%d\n", dp[n - 1][0][0][0]);
for (int i : v[n - 1][0][0][0]) printf("%d%c", i, ' ');
for (int i : v[n - 1][0][0][0]) h[i] -= a, h[i - 1] -= b, h[i + 1] -= b;
for (int i = 1; i <= n; ++i) assert(h[i] <= 0);
printf("\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 100;
int n, a, b;
int A[maxn], B[maxn];
int ans = 0x3f3f3f3f;
vector<int> G, T;
void dfs(int pos, int ret) {
if (G.size() > ans) return;
if (pos == n) {
if (A[pos] < 0) {
if (ret < ans) {
ans = ret;
T = G;
}
}
return;
}
int _a = A[pos - 1] < 0 ? 0 : (A[pos - 1] / b + 1),
_b = A[pos] < 0 ? 0 : (A[pos] / a + 1), _c = A[pos + 1] / b + 1;
for (int i = max(_a, 0); i <= max(_a, max(_b, _c)); i++) {
A[pos - 1] -= i * b, A[pos] -= i * a, A[pos + 1] -= i * b;
for (int j = 1; j <= i; j++) G.push_back(pos);
dfs(pos + 1, ret + i);
for (int j = 1; j <= i; j++) G.pop_back();
A[pos - 1] += i * b, A[pos] += i * a, A[pos + 1] += i * b;
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
dfs(2, 0);
cout << ans << endl;
for (auto it : T) cout << it << " ";
puts("");
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 100;
int n, a, b;
int A[maxn], B[maxn];
int ans = 0x3f3f3f3f;
vector<int> G, T;
void dfs(int pos, int ret) {
if (G.size() > ans) return;
if (pos == n) {
if (A[pos] < 0) {
if (ret < ans) {
ans = ret;
T = G;
}
}
return;
}
int _a = A[pos - 1] < 0 ? 0 : (A[pos - 1] / b + 1),
_b = A[pos] < 0 ? 0 : (A[pos] / a + 1), _c = A[pos + 1] / b + 1;
for (int i = max(_a, 0); i <= max(_a, max(_b, _c)); i++) {
A[pos - 1] -= i * b, A[pos] -= i * a, A[pos + 1] -= i * b;
for (int j = 1; j <= i; j++) G.push_back(pos);
dfs(pos + 1, ret + i);
for (int j = 1; j <= i; j++) G.pop_back();
A[pos - 1] += i * b, A[pos] += i * a, A[pos + 1] += i * b;
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
dfs(2, 0);
cout << ans << endl;
for (auto it : T) cout << it << " ";
puts("");
}
```
|
#include <bits/stdc++.h>
using namespace std;
int fireball1, fireball2, health[100], attack[100], attack1[100];
int n, sum = 2e+8;
void dfs(int x, int y) {
if (y >= sum) return;
if (x == n) {
sum = y;
for (int i = 1; i <= n; i++) attack[i] = attack1[i];
return;
}
for (int i = 0; i <= 100; i++) {
if (y + i > sum) break;
if (health[x - 1] - fireball2 * i >= 0) continue;
if (x == n - 1)
if (health[n] - fireball2 * i >= 0) continue;
attack1[x] = i;
health[x - 1] -= fireball2 * i;
health[x] -= fireball1 * i;
health[x + 1] -= fireball2 * i;
dfs(x + 1, y + i);
health[x - 1] += fireball2 * i;
health[x] += fireball1 * i;
health[x + 1] += fireball2 * i;
if (health[x] - fireball1 * i < 0 && health[x + 1] - fireball2 * i < 0)
break;
}
}
int main() {
scanf("%d%d%d", &n, &fireball1, &fireball2);
for (int i = 1; i <= n; i++) scanf("%d", &health[i]);
dfs(2, 0);
printf("%d\n", sum);
for (int i = 2; i < n; i++)
for (int j = 1; j <= attack[i]; j++) printf("%d ", i);
}
|
### Prompt
In cpp, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int fireball1, fireball2, health[100], attack[100], attack1[100];
int n, sum = 2e+8;
void dfs(int x, int y) {
if (y >= sum) return;
if (x == n) {
sum = y;
for (int i = 1; i <= n; i++) attack[i] = attack1[i];
return;
}
for (int i = 0; i <= 100; i++) {
if (y + i > sum) break;
if (health[x - 1] - fireball2 * i >= 0) continue;
if (x == n - 1)
if (health[n] - fireball2 * i >= 0) continue;
attack1[x] = i;
health[x - 1] -= fireball2 * i;
health[x] -= fireball1 * i;
health[x + 1] -= fireball2 * i;
dfs(x + 1, y + i);
health[x - 1] += fireball2 * i;
health[x] += fireball1 * i;
health[x + 1] += fireball2 * i;
if (health[x] - fireball1 * i < 0 && health[x + 1] - fireball2 * i < 0)
break;
}
}
int main() {
scanf("%d%d%d", &n, &fireball1, &fireball2);
for (int i = 1; i <= n; i++) scanf("%d", &health[i]);
dfs(2, 0);
printf("%d\n", sum);
for (int i = 2; i < n; i++)
for (int j = 1; j <= attack[i]; j++) printf("%d ", i);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[11];
int mi[11];
int cop[11];
bool used[11];
vector<int> t;
int need(int i) {
int q1 = max(max((h[i] + a - 1) / a, (h[i - 1] + b - 1) / b),
(h[i + 1] + b - 1) / b);
h[i - 1] -= q1 * b;
h[i + 1] -= q1 * b;
h[i] -= q1 * a;
return q1;
}
int ch(int q) {
int an = 0;
for (int i = 0; i < t.size(); i++) {
mi[t[i]] = q % 17;
q = q / 17;
h[t[i]] -= mi[t[i]] * a;
h[t[i] - 1] -= mi[t[i]] * b;
h[t[i] + 1] -= mi[t[i]] * b;
an += mi[t[i]];
}
for (int i = 1; i <= n; i++) {
if (h[i] < 0) h[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (used[i]) {
an += need(i);
}
}
bool ok = false;
for (int i = 1; i <= n; i++) {
if (h[i] > 0) ok = true;
}
for (int i = 1; i <= n; i++) h[i] = cop[i];
if (ok) return -1;
return an;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> h[i];
h[i]++;
cop[i] = h[i];
}
for (int i = 2; i < n; i += 3) used[i] = true;
for (int i = 2; i < n; i++) {
if (!used[i]) t.push_back(i);
}
int p = 1;
for (int i = 0; i < t.size(); i++) {
p = p * 17;
}
int q = 0;
int ans = 10000;
int cur;
while (q < p) {
if (ch(q) != -1) {
if (ans > ch(q)) {
ans = ch(q);
cur = q;
}
}
q++;
}
vector<int> an;
for (int i = 0; i < t.size(); i++) {
mi[t[i]] = cur % 17;
cur = cur / 17;
h[t[i]] -= mi[t[i]] * a;
h[t[i] - 1] -= mi[t[i]] * b;
h[t[i] + 1] -= mi[t[i]] * b;
for (int k = 0; k < mi[t[i]]; k++) an.push_back(t[i]);
}
for (int i = 1; i <= n; i++) {
if (h[i] < 0) h[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (used[i]) {
int z1 = need(i);
for (int k = 0; k < z1; k++) an.push_back(i);
}
}
cout << an.size() << "\n";
for (int i = 0; i < an.size(); i++) cout << an[i] << " ";
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[11];
int mi[11];
int cop[11];
bool used[11];
vector<int> t;
int need(int i) {
int q1 = max(max((h[i] + a - 1) / a, (h[i - 1] + b - 1) / b),
(h[i + 1] + b - 1) / b);
h[i - 1] -= q1 * b;
h[i + 1] -= q1 * b;
h[i] -= q1 * a;
return q1;
}
int ch(int q) {
int an = 0;
for (int i = 0; i < t.size(); i++) {
mi[t[i]] = q % 17;
q = q / 17;
h[t[i]] -= mi[t[i]] * a;
h[t[i] - 1] -= mi[t[i]] * b;
h[t[i] + 1] -= mi[t[i]] * b;
an += mi[t[i]];
}
for (int i = 1; i <= n; i++) {
if (h[i] < 0) h[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (used[i]) {
an += need(i);
}
}
bool ok = false;
for (int i = 1; i <= n; i++) {
if (h[i] > 0) ok = true;
}
for (int i = 1; i <= n; i++) h[i] = cop[i];
if (ok) return -1;
return an;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> h[i];
h[i]++;
cop[i] = h[i];
}
for (int i = 2; i < n; i += 3) used[i] = true;
for (int i = 2; i < n; i++) {
if (!used[i]) t.push_back(i);
}
int p = 1;
for (int i = 0; i < t.size(); i++) {
p = p * 17;
}
int q = 0;
int ans = 10000;
int cur;
while (q < p) {
if (ch(q) != -1) {
if (ans > ch(q)) {
ans = ch(q);
cur = q;
}
}
q++;
}
vector<int> an;
for (int i = 0; i < t.size(); i++) {
mi[t[i]] = cur % 17;
cur = cur / 17;
h[t[i]] -= mi[t[i]] * a;
h[t[i] - 1] -= mi[t[i]] * b;
h[t[i] + 1] -= mi[t[i]] * b;
for (int k = 0; k < mi[t[i]]; k++) an.push_back(t[i]);
}
for (int i = 1; i <= n; i++) {
if (h[i] < 0) h[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (used[i]) {
int z1 = need(i);
for (int k = 0; k < z1; k++) an.push_back(i);
}
}
cout << an.size() << "\n";
for (int i = 0; i < an.size(); i++) cout << an[i] << " ";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
void nop() { int a = 5; };
int n, a, b, u, ma;
int d[20], e[20], f[20];
int st, best, cur;
void out() {
cout << st + best << endl;
for (int i = 2; i < n; i++)
for (int j = 0; j < f[i]; j++) cout << i << " ";
};
void rec(int p) {
if (p == n) {
bool b = 1;
if (cur >= best) return;
for (int i = 2; i < n; i++)
if (d[i] >= 0) {
b = 0;
break;
};
if (b) {
best = cur;
for (int i = 2; i < n; i++) f[i] = e[i];
};
return;
};
rec(p + 1);
int i;
for (i = 1;; i++) {
d[p - 1] -= b;
d[p] -= a;
e[p]++;
d[p + 1] -= b;
cur++;
if (d[p - 1] < 0 && d[p] < 0 && d[p + 1] < 0) {
rec(p + 1);
break;
} else
rec(p + 1);
};
cur -= i;
d[p - 1] += b * i;
d[p] += a * i;
e[p] -= i;
d[p + 1] += b * i;
};
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> d[i];
if (d[i] > ma) ma = d[i];
};
if (n == 3) {
while (d[1] >= 0 || d[2] >= 0 || d[3] >= 0) {
d[1] -= b;
d[2] -= a;
f[2]++;
d[3] -= b;
st++;
};
out();
return 0;
};
while (d[1] >= 0) {
d[1] -= b;
d[2] -= a;
e[2]++;
d[3] -= b;
st++;
};
while (d[n] >= 0) {
d[n - 2] -= b;
d[n - 1] -= a;
e[n - 1]++;
d[n] -= b;
st++;
};
best = 1000000;
rec(2);
out();
return 0;
};
|
### Prompt
Please formulate a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
void nop() { int a = 5; };
int n, a, b, u, ma;
int d[20], e[20], f[20];
int st, best, cur;
void out() {
cout << st + best << endl;
for (int i = 2; i < n; i++)
for (int j = 0; j < f[i]; j++) cout << i << " ";
};
void rec(int p) {
if (p == n) {
bool b = 1;
if (cur >= best) return;
for (int i = 2; i < n; i++)
if (d[i] >= 0) {
b = 0;
break;
};
if (b) {
best = cur;
for (int i = 2; i < n; i++) f[i] = e[i];
};
return;
};
rec(p + 1);
int i;
for (i = 1;; i++) {
d[p - 1] -= b;
d[p] -= a;
e[p]++;
d[p + 1] -= b;
cur++;
if (d[p - 1] < 0 && d[p] < 0 && d[p + 1] < 0) {
rec(p + 1);
break;
} else
rec(p + 1);
};
cur -= i;
d[p - 1] += b * i;
d[p] += a * i;
e[p] -= i;
d[p + 1] += b * i;
};
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> d[i];
if (d[i] > ma) ma = d[i];
};
if (n == 3) {
while (d[1] >= 0 || d[2] >= 0 || d[3] >= 0) {
d[1] -= b;
d[2] -= a;
f[2]++;
d[3] -= b;
st++;
};
out();
return 0;
};
while (d[1] >= 0) {
d[1] -= b;
d[2] -= a;
e[2]++;
d[3] -= b;
st++;
};
while (d[n] >= 0) {
d[n - 2] -= b;
d[n - 1] -= a;
e[n - 1]++;
d[n] -= b;
st++;
};
best = 1000000;
rec(2);
out();
return 0;
};
```
|
#include <bits/stdc++.h>
using namespace std;
int arr[20];
int mem[20][20][20];
int n, a, b;
int calc(int ind, int p, int c) {
int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];
int& res = mem[ind][p][c];
if (res != -1) return res;
if (ind == n - 2) {
res = 0;
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
++res;
x0 -= b;
x2 -= b;
x1 -= a;
}
return res;
}
res = ((int)1e9);
int cnt = 0;
while (x0 >= 0) {
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
}
res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));
}
return res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));
}
int sol[20 * 20 * 20];
int sz;
void build(int ind, int p, int c) {
int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];
if (ind == n - 2) {
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
sol[sz++] = ind + 1;
x0 -= b;
x2 -= b;
x1 -= a;
}
return;
}
int cnt = 0;
while (x0 >= 0) {
sol[sz++] = ind + 1;
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
}
if (calc(ind, p, c) ==
cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {
build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);
return;
}
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
sol[sz++] = ind + 1;
if (calc(ind, p, c) ==
cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {
build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);
return;
}
}
if (calc(ind, p, c) ==
cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {
build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);
return;
}
}
int main() {
while (scanf("%d%d%d", &n, &a, &b) != -1) {
for (int i = 0; i < n; ++i) scanf("%d", arr + i);
memset(mem, -1, sizeof mem);
int res = calc(1, 0, 0);
printf("%d\n", res);
sz = 0;
build(1, 0, 0);
for (int i = 0; i < sz; ++i) printf(i ? " %d" : "%d", sol[i]);
printf("\n");
fflush(stdout);
}
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int arr[20];
int mem[20][20][20];
int n, a, b;
int calc(int ind, int p, int c) {
int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];
int& res = mem[ind][p][c];
if (res != -1) return res;
if (ind == n - 2) {
res = 0;
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
++res;
x0 -= b;
x2 -= b;
x1 -= a;
}
return res;
}
res = ((int)1e9);
int cnt = 0;
while (x0 >= 0) {
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
}
res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));
}
return res = min(res, cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2));
}
int sol[20 * 20 * 20];
int sz;
void build(int ind, int p, int c) {
int x0 = arr[ind - 1] - p, x1 = arr[ind] - c, x2 = arr[ind + 1];
if (ind == n - 2) {
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
sol[sz++] = ind + 1;
x0 -= b;
x2 -= b;
x1 -= a;
}
return;
}
int cnt = 0;
while (x0 >= 0) {
sol[sz++] = ind + 1;
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
}
if (calc(ind, p, c) ==
cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {
build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);
return;
}
while (x0 >= 0 || x1 >= 0 || x2 >= 0) {
++cnt;
x0 -= b;
x2 -= b;
x1 -= a;
sol[sz++] = ind + 1;
if (calc(ind, p, c) ==
cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {
build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);
return;
}
}
if (calc(ind, p, c) ==
cnt + calc(ind + 1, arr[ind] - x1, arr[ind + 1] - x2)) {
build(ind + 1, arr[ind] - x1, arr[ind + 1] - x2);
return;
}
}
int main() {
while (scanf("%d%d%d", &n, &a, &b) != -1) {
for (int i = 0; i < n; ++i) scanf("%d", arr + i);
memset(mem, -1, sizeof mem);
int res = calc(1, 0, 0);
printf("%d\n", res);
sz = 0;
build(1, 0, 0);
for (int i = 0; i < sz; ++i) printf(i ? " %d" : "%d", sol[i]);
printf("\n");
fflush(stdout);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
vector<int> q, v;
long long n, a, b, m[50], ans = 99999999, aa[50];
void dfs(long long idx, long long sum) {
if (sum >= ans) return;
if (idx == n) {
if (m[n] < 0) {
ans = min(ans, sum);
v = q;
}
return;
}
long long t = max(m[idx - 1] / b, max((m[idx]) / a, m[idx + 1] / b)) + 1;
for (long long i = 0; i <= t; i++) {
if (m[idx - 1] >= b * i) continue;
m[idx] -= a * i;
m[idx - 1] -= b * i;
m[idx + 1] -= b * i;
for (int j = 1; j <= i; j++) {
q.push_back(idx);
}
dfs(idx + 1, sum + i);
for (int j = 1; j <= i; j++) {
q.pop_back();
}
m[idx] += a * i;
m[idx - 1] += b * i;
m[idx + 1] += b * i;
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> m[i];
}
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < ans; i++) {
cout << v[i] << " ";
}
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> q, v;
long long n, a, b, m[50], ans = 99999999, aa[50];
void dfs(long long idx, long long sum) {
if (sum >= ans) return;
if (idx == n) {
if (m[n] < 0) {
ans = min(ans, sum);
v = q;
}
return;
}
long long t = max(m[idx - 1] / b, max((m[idx]) / a, m[idx + 1] / b)) + 1;
for (long long i = 0; i <= t; i++) {
if (m[idx - 1] >= b * i) continue;
m[idx] -= a * i;
m[idx - 1] -= b * i;
m[idx + 1] -= b * i;
for (int j = 1; j <= i; j++) {
q.push_back(idx);
}
dfs(idx + 1, sum + i);
for (int j = 1; j <= i; j++) {
q.pop_back();
}
m[idx] += a * i;
m[idx - 1] += b * i;
m[idx + 1] += b * i;
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> m[i];
}
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < ans; i++) {
cout << v[i] << " ";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int INF = 1e6;
int n, a, b;
int h[N], dp[N][N][N];
pair<int, int> pre[N][N][N];
void output(int id, int x, int y) {
if (id == 1) return;
int _x = pre[id + 1][x][y].first, _y = pre[id + 1][x][y].second;
output(id - 1, _x, _y);
for (int i = 0; i < dp[id + 1][x][y] - dp[id][_x][_y]; ++i) printf("%d ", id);
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]), ++h[i];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
for (int k = 0; k < N; ++k) dp[i][j][k] = INF;
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; ++i)
for (int j = 0; j <= h[i - 1]; ++j)
for (int k = 0; k <= h[i]; ++k) {
if (dp[i][j][k] == INF) continue;
int bot = (j + b - 1) / b;
int top = max(bot, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int l = bot; l <= top; ++l) {
int _j = max(0, k - l * a);
int _k = max(0, h[i + 1] - l * b);
if (dp[i + 1][_j][_k] > dp[i][j][k] + l) {
dp[i + 1][_j][_k] = dp[i][j][k] + l;
pre[i + 1][_j][_k] = pair<int, int>(j, k);
}
}
}
printf("%d\n", dp[n][0][0]);
output(n - 1, 0, 0);
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int INF = 1e6;
int n, a, b;
int h[N], dp[N][N][N];
pair<int, int> pre[N][N][N];
void output(int id, int x, int y) {
if (id == 1) return;
int _x = pre[id + 1][x][y].first, _y = pre[id + 1][x][y].second;
output(id - 1, _x, _y);
for (int i = 0; i < dp[id + 1][x][y] - dp[id][_x][_y]; ++i) printf("%d ", id);
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]), ++h[i];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
for (int k = 0; k < N; ++k) dp[i][j][k] = INF;
dp[2][h[1]][h[2]] = 0;
for (int i = 2; i < n; ++i)
for (int j = 0; j <= h[i - 1]; ++j)
for (int k = 0; k <= h[i]; ++k) {
if (dp[i][j][k] == INF) continue;
int bot = (j + b - 1) / b;
int top = max(bot, max((k + a - 1) / a, (h[i + 1] + b - 1) / b));
for (int l = bot; l <= top; ++l) {
int _j = max(0, k - l * a);
int _k = max(0, h[i + 1] - l * b);
if (dp[i + 1][_j][_k] > dp[i][j][k] + l) {
dp[i + 1][_j][_k] = dp[i][j][k] + l;
pre[i + 1][_j][_k] = pair<int, int>(j, k);
}
}
}
printf("%d\n", dp[n][0][0]);
output(n - 1, 0, 0);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h[30], f[30][30][30], from[30][30][30];
template <typename T>
inline T read() {
T x = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * w;
}
int main() {
n = read<int>(), a = read<int>(), b = read<int>();
for (int i = 1; i <= n; i++) h[i] = read<int>();
memset(f, 0x3f, sizeof(f));
for (int i = h[1] / b + 1; i <= 20; i++) f[1][0][i] = i;
for (int i = 2; i <= n; i++)
for (int j = 0; j <= 20; j++)
for (int k = 0; k <= 20; k++)
for (int l = 0; l <= 20; l++)
if ((j + l) * b + k * a > h[i] && f[i - 1][j][k] < 0x3f3f3f3f)
if (f[i - 1][j][k] + l < f[i][k][l])
f[i][k][l] = f[i - 1][j][k] + l, from[i][k][l] = j;
printf("%d\n", f[n][0][0]);
int l = 0, r = 0;
while (n) {
for (int i = 1; i <= l; i++) printf("%d ", n);
int tmp = from[n][l][r];
r = l, l = tmp;
n--;
}
puts("");
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h[30], f[30][30][30], from[30][30][30];
template <typename T>
inline T read() {
T x = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * w;
}
int main() {
n = read<int>(), a = read<int>(), b = read<int>();
for (int i = 1; i <= n; i++) h[i] = read<int>();
memset(f, 0x3f, sizeof(f));
for (int i = h[1] / b + 1; i <= 20; i++) f[1][0][i] = i;
for (int i = 2; i <= n; i++)
for (int j = 0; j <= 20; j++)
for (int k = 0; k <= 20; k++)
for (int l = 0; l <= 20; l++)
if ((j + l) * b + k * a > h[i] && f[i - 1][j][k] < 0x3f3f3f3f)
if (f[i - 1][j][k] + l < f[i][k][l])
f[i][k][l] = f[i - 1][j][k] + l, from[i][k][l] = j;
printf("%d\n", f[n][0][0]);
int l = 0, r = 0;
while (n) {
for (int i = 1; i <= l; i++) printf("%d ", n);
int tmp = from[n][l][r];
r = l, l = tmp;
n--;
}
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e1 + 5, maxm = 15 * 10 + 5;
int n, a, b, h[maxn], sum, ans;
int pos[maxm], val[maxm];
int rad() {
int ret = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
return ret * f;
}
void check() {
int yu = max(h[n - 1] / a + (h[n - 1] >= 0), h[n] / b + (h[n] >= 0));
for (int i = 1; i <= yu; ++i) pos[++sum] = n - 1;
if (ans > sum) {
for (int i = 1; i <= sum; ++i) val[i] = pos[i];
ans = sum;
}
sum -= yu;
}
void dfs(int now) {
if (now > n - 1) {
check();
return;
}
if (h[now - 1] < 0) dfs(now + 1);
int i = 1, lst = sum, A = h[now - 1], B = h[now], C = h[now + 1];
while (true) {
h[now] -= a;
h[now - 1] -= b;
h[now + 1] -= b;
pos[++sum] = now;
if (h[now - 1] < 0) dfs(now + 1);
if ((h[now - 1] < 0 && h[now] < 0) || sum >= ans) {
sum = lst;
h[now - 1] = A, h[now] = B, h[now + 1] = C;
break;
}
}
}
int main() {
n = rad();
a = rad();
b = rad();
for (int i = 1; i <= n; ++i) h[i] = rad();
ans = 1e9;
sum = 0;
dfs(2);
printf("%d\n", ans);
for (int i = 1; i < ans; ++i) printf("%d ", val[i]);
printf("%d\n", val[ans]);
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e1 + 5, maxm = 15 * 10 + 5;
int n, a, b, h[maxn], sum, ans;
int pos[maxm], val[maxm];
int rad() {
int ret = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
return ret * f;
}
void check() {
int yu = max(h[n - 1] / a + (h[n - 1] >= 0), h[n] / b + (h[n] >= 0));
for (int i = 1; i <= yu; ++i) pos[++sum] = n - 1;
if (ans > sum) {
for (int i = 1; i <= sum; ++i) val[i] = pos[i];
ans = sum;
}
sum -= yu;
}
void dfs(int now) {
if (now > n - 1) {
check();
return;
}
if (h[now - 1] < 0) dfs(now + 1);
int i = 1, lst = sum, A = h[now - 1], B = h[now], C = h[now + 1];
while (true) {
h[now] -= a;
h[now - 1] -= b;
h[now + 1] -= b;
pos[++sum] = now;
if (h[now - 1] < 0) dfs(now + 1);
if ((h[now - 1] < 0 && h[now] < 0) || sum >= ans) {
sum = lst;
h[now - 1] = A, h[now] = B, h[now + 1] = C;
break;
}
}
}
int main() {
n = rad();
a = rad();
b = rad();
for (int i = 1; i <= n; ++i) h[i] = rad();
ans = 1e9;
sum = 0;
dfs(2);
printf("%d\n", ans);
for (int i = 1; i < ans; ++i) printf("%d ", val[i]);
printf("%d\n", val[ans]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long n, a, b;
vector<long long> v(11);
long long dp[12][10000][21];
vector<long long> ans;
long long f(long long i, long long tak, long long moves) {
if (i == n - 1) return 0;
if (dp[i][tak][moves] != -1) return dp[i][tak][moves];
long long left = v[i - 1] - tak;
long long mi = 0;
if (left > 0) mi = left / b + (left % b != 0);
long long ans = 1e18;
for (long long j = mi; j <= 20; j++)
ans = min(ans, j + f(i + 1, j * a + moves * b, j));
return dp[i][tak][moves] = ans;
}
void path(long long i, long long tak, long long moves) {
if (i == n - 1) return;
long long left = v[i - 1] - tak;
long long mi = 0;
if (left > 0) mi = left / b + (left % b != 0);
long long ans1 = 1e18;
long long ind = -1;
for (long long j = mi; j <= 20; j++) {
if (ans1 > j + f(i + 1, j * a + moves * b, j)) ind = j;
ans1 = min(ans1, j + f(i + 1, j * a + moves * b, j));
}
for (long long j = 0; j < ind; j++) ans.push_back(i + 1);
path(i + 1, ind * a + moves * b, ind);
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n >> a >> b;
for (long long i = 0; i < n; i++) {
cin >> v[i];
v[i]++;
}
long long ans1 = v[0] / b + (v[0] % b != 0);
for (long long i = 0; i < ans1; i++) ans.push_back(2);
v[1] = max((long long)0, v[1] - ans1 * a);
v[2] = max((long long)0, v[2] - ans1 * b);
long long ans2 = v[n - 1] / b + (v[n - 1] % b != 0);
v[n - 2] = max((long long)0, v[n - 2] - ans2 * a);
v[n - 3] = max((long long)0, v[n - 3] - ans2 * b);
memset(dp, -1, sizeof(dp));
v[0] = 0;
v[n - 1] = 0;
f(1, 0, 0);
path(1, 0, 0);
for (long long i = 0; i < ans2; i++) ans.push_back(n - 1);
cout << ans.size() << '\n';
for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
|
### Prompt
Generate a CPP solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, a, b;
vector<long long> v(11);
long long dp[12][10000][21];
vector<long long> ans;
long long f(long long i, long long tak, long long moves) {
if (i == n - 1) return 0;
if (dp[i][tak][moves] != -1) return dp[i][tak][moves];
long long left = v[i - 1] - tak;
long long mi = 0;
if (left > 0) mi = left / b + (left % b != 0);
long long ans = 1e18;
for (long long j = mi; j <= 20; j++)
ans = min(ans, j + f(i + 1, j * a + moves * b, j));
return dp[i][tak][moves] = ans;
}
void path(long long i, long long tak, long long moves) {
if (i == n - 1) return;
long long left = v[i - 1] - tak;
long long mi = 0;
if (left > 0) mi = left / b + (left % b != 0);
long long ans1 = 1e18;
long long ind = -1;
for (long long j = mi; j <= 20; j++) {
if (ans1 > j + f(i + 1, j * a + moves * b, j)) ind = j;
ans1 = min(ans1, j + f(i + 1, j * a + moves * b, j));
}
for (long long j = 0; j < ind; j++) ans.push_back(i + 1);
path(i + 1, ind * a + moves * b, ind);
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n >> a >> b;
for (long long i = 0; i < n; i++) {
cin >> v[i];
v[i]++;
}
long long ans1 = v[0] / b + (v[0] % b != 0);
for (long long i = 0; i < ans1; i++) ans.push_back(2);
v[1] = max((long long)0, v[1] - ans1 * a);
v[2] = max((long long)0, v[2] - ans1 * b);
long long ans2 = v[n - 1] / b + (v[n - 1] % b != 0);
v[n - 2] = max((long long)0, v[n - 2] - ans2 * a);
v[n - 3] = max((long long)0, v[n - 3] - ans2 * b);
memset(dp, -1, sizeof(dp));
v[0] = 0;
v[n - 1] = 0;
f(1, 0, 0);
path(1, 0, 0);
for (long long i = 0; i < ans2; i++) ans.push_back(n - 1);
cout << ans.size() << '\n';
for (long long i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h[44], res[44], cnt[44], ans = 1000 * 1000 * 1000;
void solve(int pos) {
int hcopy[44], ccopy[44];
for (int i = 1; i <= n; i++) hcopy[i] = h[i], ccopy[i] = cnt[i];
if (pos == n - 1) {
while (h[pos - 1] >= 0 || h[pos] >= 0 || h[pos + 1] >= 0)
h[pos - 1] -= b, h[pos] -= a, h[pos + 1] -= b, cnt[pos]++;
int sum = 0;
for (int i = 1; i <= n; i++) sum += cnt[i];
if (sum < ans) {
ans = sum;
for (int i = 1; i <= n; i++) res[i] = cnt[i];
}
for (int i = 1; i <= n; i++) cnt[i] = ccopy[i], h[i] = hcopy[i];
return;
} else {
while (h[pos - 1] >= 0)
h[pos - 1] -= b, h[pos] -= a, h[pos + 1] -= b, cnt[pos]++;
solve(pos + 1);
while (h[pos] >= 0) {
h[pos] -= a, h[pos + 1] -= b, cnt[pos]++;
solve(pos + 1);
}
for (int i = 1; i <= n; i++) h[i] = hcopy[i], cnt[i] = ccopy[i];
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
solve(2);
printf("%d\n", ans);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= res[i]; j++) printf("%d ", i);
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, h[44], res[44], cnt[44], ans = 1000 * 1000 * 1000;
void solve(int pos) {
int hcopy[44], ccopy[44];
for (int i = 1; i <= n; i++) hcopy[i] = h[i], ccopy[i] = cnt[i];
if (pos == n - 1) {
while (h[pos - 1] >= 0 || h[pos] >= 0 || h[pos + 1] >= 0)
h[pos - 1] -= b, h[pos] -= a, h[pos + 1] -= b, cnt[pos]++;
int sum = 0;
for (int i = 1; i <= n; i++) sum += cnt[i];
if (sum < ans) {
ans = sum;
for (int i = 1; i <= n; i++) res[i] = cnt[i];
}
for (int i = 1; i <= n; i++) cnt[i] = ccopy[i], h[i] = hcopy[i];
return;
} else {
while (h[pos - 1] >= 0)
h[pos - 1] -= b, h[pos] -= a, h[pos + 1] -= b, cnt[pos]++;
solve(pos + 1);
while (h[pos] >= 0) {
h[pos] -= a, h[pos + 1] -= b, cnt[pos]++;
solve(pos + 1);
}
for (int i = 1; i <= n; i++) h[i] = hcopy[i], cnt[i] = ccopy[i];
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
solve(2);
printf("%d\n", ans);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= res[i]; j++) printf("%d ", i);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b, f[20] = {0}, SUM = 454345;
vector<int> U;
vector<int> H;
void rec(vector<int> V, int X) {
int URT = V.size();
if (URT >= SUM) return;
bool T = 0;
for (int i = 2; i < n; i++) {
if (f[i] >= 0) {
T = 1;
break;
}
}
if (T == 0) {
if (URT < SUM) {
SUM = URT;
H = V;
}
return;
}
for (int i = X; i < n; i++) {
if (f[i] >= 0 || f[i - 1] >= 0 || f[i + 1] >= 0) {
f[i] -= a;
f[i + 1] -= b;
f[i - 1] -= b;
V.push_back(i);
rec(V, i);
V.erase(V.begin() + URT);
f[i] += a;
f[i + 1] += b;
f[i - 1] += b;
}
}
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
while (f[1] >= 0) {
f[3] -= b;
f[2] -= a;
f[1] -= b;
U.push_back(2);
}
while (f[n] >= 0) {
f[n] -= b;
f[n - 1] -= a;
f[n - 2] -= b;
U.push_back(n - 1);
}
rec(H, 2);
printf("%d\n", H.size() + U.size());
for (int i = 0; i < U.size(); i++) printf("%d ", U[i]);
for (int i = 0; i < H.size(); i++) printf("%d ", H[i]);
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, f[20] = {0}, SUM = 454345;
vector<int> U;
vector<int> H;
void rec(vector<int> V, int X) {
int URT = V.size();
if (URT >= SUM) return;
bool T = 0;
for (int i = 2; i < n; i++) {
if (f[i] >= 0) {
T = 1;
break;
}
}
if (T == 0) {
if (URT < SUM) {
SUM = URT;
H = V;
}
return;
}
for (int i = X; i < n; i++) {
if (f[i] >= 0 || f[i - 1] >= 0 || f[i + 1] >= 0) {
f[i] -= a;
f[i + 1] -= b;
f[i - 1] -= b;
V.push_back(i);
rec(V, i);
V.erase(V.begin() + URT);
f[i] += a;
f[i + 1] += b;
f[i - 1] += b;
}
}
}
int main() {
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &f[i]);
while (f[1] >= 0) {
f[3] -= b;
f[2] -= a;
f[1] -= b;
U.push_back(2);
}
while (f[n] >= 0) {
f[n] -= b;
f[n - 1] -= a;
f[n - 2] -= b;
U.push_back(n - 1);
}
rec(H, 2);
printf("%d\n", H.size() + U.size());
for (int i = 0; i < U.size(); i++) printf("%d ", U[i]);
for (int i = 0; i < H.size(); i++) printf("%d ", H[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
pair<long long, long long> dp[12][17][17];
long long n, itself, near, h[12], die1, die2, ans = INF;
vector<int> keep[12][17][17], answer;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> itself >> near;
for (int i = 0; i < n; i++) {
cin >> h[i];
h[i]++;
}
die1 = (h[0] % near > 0) + (h[0] / near);
h[1] = max(h[1] - die1 * itself, (long long)0);
h[2] = max(h[2] - die1 * near, (long long)0);
die2 = (h[n - 1] % near > 0) + (h[n - 1] / near);
h[n - 2] = max(h[n - 2] - die2 * itself, (long long)0);
h[n - 3] = max(h[n - 3] - die2 * near, (long long)0);
for (int i = 1; i < n - 1; i++)
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++) {
if (i == 1 && j > 0) continue;
int best = INF;
for (int w = 0; w <= 15; w++)
if (dp[i - 1][w][j].second <= k * near) {
if (i - 1 == 1 && w > 0) continue;
if (best > dp[i - 1][w][j].first) {
best = dp[i - 1][w][j].first;
keep[i][j][k] = keep[i - 1][w][j];
}
}
keep[i][j][k].push_back(k);
dp[i][j][k] = make_pair(
best + k, max(h[i] - j * near - k * itself, (long long)0));
if (i == n - 2 && dp[i][j][k].second == 0 && ans > dp[i][j][k].first) {
ans = dp[i][j][k].first;
answer = keep[i][j][k];
}
}
answer[0] += die1;
answer[n - 3] += die2;
cout << ans + die1 + die2 << endl;
for (int i = 0; i < n - 2; i++)
for (int j = 0; j < answer[i]; j++) cout << i + 2 << " ";
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
pair<long long, long long> dp[12][17][17];
long long n, itself, near, h[12], die1, die2, ans = INF;
vector<int> keep[12][17][17], answer;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> itself >> near;
for (int i = 0; i < n; i++) {
cin >> h[i];
h[i]++;
}
die1 = (h[0] % near > 0) + (h[0] / near);
h[1] = max(h[1] - die1 * itself, (long long)0);
h[2] = max(h[2] - die1 * near, (long long)0);
die2 = (h[n - 1] % near > 0) + (h[n - 1] / near);
h[n - 2] = max(h[n - 2] - die2 * itself, (long long)0);
h[n - 3] = max(h[n - 3] - die2 * near, (long long)0);
for (int i = 1; i < n - 1; i++)
for (int j = 0; j <= 15; j++)
for (int k = 0; k <= 15; k++) {
if (i == 1 && j > 0) continue;
int best = INF;
for (int w = 0; w <= 15; w++)
if (dp[i - 1][w][j].second <= k * near) {
if (i - 1 == 1 && w > 0) continue;
if (best > dp[i - 1][w][j].first) {
best = dp[i - 1][w][j].first;
keep[i][j][k] = keep[i - 1][w][j];
}
}
keep[i][j][k].push_back(k);
dp[i][j][k] = make_pair(
best + k, max(h[i] - j * near - k * itself, (long long)0));
if (i == n - 2 && dp[i][j][k].second == 0 && ans > dp[i][j][k].first) {
ans = dp[i][j][k].first;
answer = keep[i][j][k];
}
}
answer[0] += die1;
answer[n - 3] += die2;
cout << ans + die1 + die2 << endl;
for (int i = 0; i < n - 2; i++)
for (int j = 0; j < answer[i]; j++) cout << i + 2 << " ";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
struct ddt {
int pos;
vector<int> attempts;
int sum;
ddt(int pos_) {
pos = pos_;
sum = 0;
}
};
int main() {
int n, A, B;
cin >> n >> A >> B;
vector<int> a(n);
for (auto& i : a) {
cin >> i;
++i;
}
int ans = 1e9;
vector<int> res;
queue<ddt> q;
q.push({1});
while (!q.empty()) {
ddt x = q.front();
q.pop();
if (x.pos == n - 1) {
if (ans > x.sum) {
ans = x.sum;
res = x.attempts;
}
continue;
}
int hits = a[x.pos - 1];
if (!x.attempts.empty()) {
hits -= x.attempts.back() * A;
}
if (x.attempts.size() > 1) {
hits -= x.attempts[x.attempts.size() - 2] * B;
}
int from = max(0, int((hits + B - 1) / B));
if (x.pos == n - 2) {
from = max(from, int((a.back() + B - 1) / B));
}
int to = from + max(0, (a[x.pos] - A * from + A - 1) / A);
for (int i = from; i <= to; ++i) {
ddt t = x;
++t.pos;
t.attempts.push_back(i);
t.sum += i;
q.push(t);
}
}
cout << ans << endl;
for (int i = 0; i < res.size(); ++i) {
for (int j = 0; j < res[i]; ++j) {
cout << 2 + i << " ";
}
}
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
struct ddt {
int pos;
vector<int> attempts;
int sum;
ddt(int pos_) {
pos = pos_;
sum = 0;
}
};
int main() {
int n, A, B;
cin >> n >> A >> B;
vector<int> a(n);
for (auto& i : a) {
cin >> i;
++i;
}
int ans = 1e9;
vector<int> res;
queue<ddt> q;
q.push({1});
while (!q.empty()) {
ddt x = q.front();
q.pop();
if (x.pos == n - 1) {
if (ans > x.sum) {
ans = x.sum;
res = x.attempts;
}
continue;
}
int hits = a[x.pos - 1];
if (!x.attempts.empty()) {
hits -= x.attempts.back() * A;
}
if (x.attempts.size() > 1) {
hits -= x.attempts[x.attempts.size() - 2] * B;
}
int from = max(0, int((hits + B - 1) / B));
if (x.pos == n - 2) {
from = max(from, int((a.back() + B - 1) / B));
}
int to = from + max(0, (a[x.pos] - A * from + A - 1) / A);
for (int i = from; i <= to; ++i) {
ddt t = x;
++t.pos;
t.attempts.push_back(i);
t.sum += i;
q.push(t);
}
}
cout << ans << endl;
for (int i = 0; i < res.size(); ++i) {
for (int j = 0; j < res[i]; ++j) {
cout << 2 + i << " ";
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
struct node {
int x, y, z, s;
} pre[12][18][18][18];
int n, a, b, dp[12][18][18][18], h[12];
vector<int> ans;
void f(int i, int x, int y, int z, int v, int xx, int yy, int zz, int s) {
x = max(0, x);
y = max(0, y);
z = max(0, z);
if (dp[i][x][y][z] > v) {
dp[i][x][y][z] = v;
pre[i][x][y][z] = (node){xx, yy, zz, s};
}
}
void find(int i, int x, int y, int z) {
node tmp = pre[i][x][y][z];
int s = tmp.s;
for (int j = 0; j < s; j++) {
ans.push_back(i);
}
if (i == 2) {
return;
}
find(i - 1, tmp.x, tmp.y, tmp.z);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
for (int i = 0; i <= n; i++) {
for (int x = 0; x <= 16; x++) {
for (int y = 0; y <= 16; y++) {
for (int z = 0; z <= 16; z++) {
dp[i][x][y][z] = inf;
}
}
}
}
f(1, h[1], h[2], h[3], 0, 0, 0, 0, 0);
for (int i = 1; i < n - 1; i++) {
int z = h[i + 2];
for (int x = 0; x <= h[i]; x++) {
for (int y = 0; y <= h[i + 1]; y++) {
int v = dp[i][x][y][z];
if (v >= inf) {
continue;
}
for (int j = (x + b - 1) / b;; j++) {
f(i + 1, y - j * a, z - j * b, h[i + 3], v + j, x, y, z, j);
if (j * a > y && j * b > z) {
break;
}
}
}
}
}
find(n - 1, 0, 0, 0);
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
printf("%d ", ans[i]);
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
struct node {
int x, y, z, s;
} pre[12][18][18][18];
int n, a, b, dp[12][18][18][18], h[12];
vector<int> ans;
void f(int i, int x, int y, int z, int v, int xx, int yy, int zz, int s) {
x = max(0, x);
y = max(0, y);
z = max(0, z);
if (dp[i][x][y][z] > v) {
dp[i][x][y][z] = v;
pre[i][x][y][z] = (node){xx, yy, zz, s};
}
}
void find(int i, int x, int y, int z) {
node tmp = pre[i][x][y][z];
int s = tmp.s;
for (int j = 0; j < s; j++) {
ans.push_back(i);
}
if (i == 2) {
return;
}
find(i - 1, tmp.x, tmp.y, tmp.z);
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
h[i]++;
}
for (int i = 0; i <= n; i++) {
for (int x = 0; x <= 16; x++) {
for (int y = 0; y <= 16; y++) {
for (int z = 0; z <= 16; z++) {
dp[i][x][y][z] = inf;
}
}
}
}
f(1, h[1], h[2], h[3], 0, 0, 0, 0, 0);
for (int i = 1; i < n - 1; i++) {
int z = h[i + 2];
for (int x = 0; x <= h[i]; x++) {
for (int y = 0; y <= h[i + 1]; y++) {
int v = dp[i][x][y][z];
if (v >= inf) {
continue;
}
for (int j = (x + b - 1) / b;; j++) {
f(i + 1, y - j * a, z - j * b, h[i + 3], v + j, x, y, z, j);
if (j * a > y && j * b > z) {
break;
}
}
}
}
}
find(n - 1, 0, 0, 0);
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
printf("%d ", ans[i]);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h[15], dp[100][100][100], n, a, b, bo[100][100][100];
const int inf = 1e5;
int rek(int x, int pr, int cr) {
if (x == n) {
if (pr < 0 && cr < 0) return 0;
return inf;
}
if (dp[x][pr + 80][cr + 80] != -1) return dp[x][pr + 80][cr + 80];
int nxt = h[x + 1], br = 0;
int &ret = dp[x][pr + 80][cr + 80];
int n1 = pr, n2 = cr;
bool f = 1;
ret = inf;
while (pr >= 0 || cr >= 0 || nxt >= 0 || f) {
if (pr < 0 && cr < 0 && nxt < 0) {
f = 0;
}
if (pr < 0) {
int o = ret;
ret = min(ret, rek(x + 1, cr, nxt) + br);
if (o != ret) {
bo[x][n1][n2] = br;
}
}
pr -= b;
cr -= a;
nxt -= b;
br++;
}
return ret;
}
void prnt(int x, int pr, int cr) {
if (x == n) return;
for (int i = 0; i < bo[x][pr][cr]; ++i) {
cout << x << ' ';
}
int k = bo[x][pr][cr];
cr -= k * a;
int nxt = h[x + 1] - k * b;
prnt(x + 1, cr, nxt);
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
memset(dp, -1, sizeof(dp));
cout << rek(2, h[1], h[2]) << endl;
prnt(2, h[1], h[2]);
cout << endl;
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h[15], dp[100][100][100], n, a, b, bo[100][100][100];
const int inf = 1e5;
int rek(int x, int pr, int cr) {
if (x == n) {
if (pr < 0 && cr < 0) return 0;
return inf;
}
if (dp[x][pr + 80][cr + 80] != -1) return dp[x][pr + 80][cr + 80];
int nxt = h[x + 1], br = 0;
int &ret = dp[x][pr + 80][cr + 80];
int n1 = pr, n2 = cr;
bool f = 1;
ret = inf;
while (pr >= 0 || cr >= 0 || nxt >= 0 || f) {
if (pr < 0 && cr < 0 && nxt < 0) {
f = 0;
}
if (pr < 0) {
int o = ret;
ret = min(ret, rek(x + 1, cr, nxt) + br);
if (o != ret) {
bo[x][n1][n2] = br;
}
}
pr -= b;
cr -= a;
nxt -= b;
br++;
}
return ret;
}
void prnt(int x, int pr, int cr) {
if (x == n) return;
for (int i = 0; i < bo[x][pr][cr]; ++i) {
cout << x << ' ';
}
int k = bo[x][pr][cr];
cr -= k * a;
int nxt = h[x + 1] - k * b;
prnt(x + 1, cr, nxt);
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) {
cin >> h[i];
}
memset(dp, -1, sizeof(dp));
cout << rek(2, h[1], h[2]) << endl;
prnt(2, h[1], h[2]);
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int ans = 9999999;
int h[100];
int a, b, n;
vector<int> V;
vector<int> V2;
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[x] < 0) {
V2 = V;
ans = times;
}
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) V.push_back(x);
dfs(x + 1, times + i);
for (int j = 0; j < i; j++) V.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < V2.size(); i++) cout << V2[i] << " ";
cout << endl;
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int ans = 9999999;
int h[100];
int a, b, n;
vector<int> V;
vector<int> V2;
void dfs(int x, int times) {
if (times >= ans) return;
if (x == n) {
if (h[x] < 0) {
V2 = V;
ans = times;
}
return;
}
for (int i = 0;
i <= max(h[x - 1] / b + 1, max(h[x] / a + 1, h[x + 1] / b + 1)); i++) {
if (h[x - 1] < b * i) {
h[x - 1] -= b * i;
h[x] -= a * i;
h[x + 1] -= b * i;
for (int j = 0; j < i; j++) V.push_back(x);
dfs(x + 1, times + i);
for (int j = 0; j < i; j++) V.pop_back();
h[x - 1] += b * i;
h[x] += a * i;
h[x + 1] += b * i;
}
}
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
dfs(2, 0);
cout << ans << endl;
for (int i = 0; i < V2.size(); i++) cout << V2[i] << " ";
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string i2s(long long x) {
ostringstream o;
o << x;
return o.str();
}
long long s2i(string s) {
istringstream i(s);
long long x;
i >> x;
return x;
}
int n, b, a;
int h[15];
vector<int> res, z;
void initialize() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
}
void go(int i) {
if (h[i - 1] >= 0) {
h[i - 1] -= b;
h[i] -= a;
h[i + 1] -= b;
z.push_back(i);
go(i);
h[i - 1] += b;
h[i] += a;
h[i + 1] += b;
z.pop_back();
return;
}
if (i == n - 1) {
if (h[i - 1] < 0 && h[i] < 0 && h[i + 1] < 0) {
if (res.empty() || res.size() > z.size()) res = z;
return;
}
}
if (i + 1 < n) go(i + 1);
if (h[i] >= 0 || (i == n - 1 && h[n] >= 0)) {
h[i - 1] -= b;
h[i] -= a;
h[i + 1] -= b;
z.push_back(i);
go(i);
z.pop_back();
h[i - 1] += b;
h[i] += a;
h[i + 1] += b;
}
}
void solve() {
go(2);
cout << res.size() << endl;
for (int i = 0; i < res.size(); i++) cout << res[i] << " ";
}
int main() {
initialize();
solve();
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string i2s(long long x) {
ostringstream o;
o << x;
return o.str();
}
long long s2i(string s) {
istringstream i(s);
long long x;
i >> x;
return x;
}
int n, b, a;
int h[15];
vector<int> res, z;
void initialize() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
}
void go(int i) {
if (h[i - 1] >= 0) {
h[i - 1] -= b;
h[i] -= a;
h[i + 1] -= b;
z.push_back(i);
go(i);
h[i - 1] += b;
h[i] += a;
h[i + 1] += b;
z.pop_back();
return;
}
if (i == n - 1) {
if (h[i - 1] < 0 && h[i] < 0 && h[i + 1] < 0) {
if (res.empty() || res.size() > z.size()) res = z;
return;
}
}
if (i + 1 < n) go(i + 1);
if (h[i] >= 0 || (i == n - 1 && h[n] >= 0)) {
h[i - 1] -= b;
h[i] -= a;
h[i + 1] -= b;
z.push_back(i);
go(i);
z.pop_back();
h[i - 1] += b;
h[i] += a;
h[i + 1] += b;
}
}
void solve() {
go(2);
cout << res.size() << endl;
for (int i = 0; i < res.size(); i++) cout << res[i] << " ";
}
int main() {
initialize();
solve();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
int x[100];
stack<int> st;
int n, a, b;
int best = 100000;
int nums[100], sum[100], best2[100];
bool z;
void rec(int k) {
if (k > n - 1) {
bool z = true;
int cnt = 0;
for (int i = 2; i <= n - 1; i++) sum[i] = 0;
for (int i = 2; i <= n - 1; i++) {
cnt += nums[i];
sum[i - 1] += nums[i] * b;
sum[i] += nums[i] * a;
sum[i + 1] += nums[i] * b;
}
for (int i = 2; i <= n - 1; i++) {
if (sum[i] <= x[i]) z = false;
}
if (z && best > cnt) {
best = cnt;
for (int i = 2; i <= n - 1; i++) best2[i] = nums[i];
}
} else {
int to;
to = x[k] / a + 2;
to = max(to, 0);
for (int i = 0; i <= to; i++) {
nums[k] = i;
rec(k + 1);
}
}
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> x[i];
while (x[1] >= 0) {
st.push(2);
x[1] -= b;
x[2] -= a;
x[3] -= b;
}
while (x[n] >= 0) {
st.push(n - 1);
x[n - 2] -= b;
x[n - 1] -= a;
x[n] -= b;
}
rec(2);
for (int i = 2; i <= n - 1; i++) {
for (int j = 1; j <= best2[i]; j++) st.push(i);
}
cout << st.size() << "\n";
while (!st.empty()) {
cout << st.top() << " ";
st.pop();
}
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
int x[100];
stack<int> st;
int n, a, b;
int best = 100000;
int nums[100], sum[100], best2[100];
bool z;
void rec(int k) {
if (k > n - 1) {
bool z = true;
int cnt = 0;
for (int i = 2; i <= n - 1; i++) sum[i] = 0;
for (int i = 2; i <= n - 1; i++) {
cnt += nums[i];
sum[i - 1] += nums[i] * b;
sum[i] += nums[i] * a;
sum[i + 1] += nums[i] * b;
}
for (int i = 2; i <= n - 1; i++) {
if (sum[i] <= x[i]) z = false;
}
if (z && best > cnt) {
best = cnt;
for (int i = 2; i <= n - 1; i++) best2[i] = nums[i];
}
} else {
int to;
to = x[k] / a + 2;
to = max(to, 0);
for (int i = 0; i <= to; i++) {
nums[k] = i;
rec(k + 1);
}
}
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> x[i];
while (x[1] >= 0) {
st.push(2);
x[1] -= b;
x[2] -= a;
x[3] -= b;
}
while (x[n] >= 0) {
st.push(n - 1);
x[n - 2] -= b;
x[n - 1] -= a;
x[n] -= b;
}
rec(2);
for (int i = 2; i <= n - 1; i++) {
for (int j = 1; j <= best2[i]; j++) st.push(i);
}
cout << st.size() << "\n";
while (!st.empty()) {
cout << st.top() << " ";
st.pop();
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int num[15];
int fa(int x) {
if (x < 0) return 0;
return x / a + 1;
}
int fb(int x) {
if (x < 0) return 0;
return x / b + 1;
}
int ans[15], tot;
int temp[15];
void dfs(int pos, int cnt) {
if (pos == n - 1) {
if (num[pos] >= 0) {
cnt += fa(num[pos]);
temp[pos] += fa(num[pos]);
}
if (cnt < tot) {
tot = cnt;
for (int i = 2; i < n; i++) {
ans[i] = temp[i];
if (ans[i] < 0) cout << '+';
}
}
return;
}
if (num[pos] < 0)
dfs(pos + 1, cnt);
else {
int f = fa(num[pos]);
for (int i = 0; i <= f; i++) {
temp[pos] += i;
temp[pos + 1] += fb(num[pos] - i * a);
num[pos + 1] -= a * fb(num[pos] - i * a) + i * b;
num[pos + 2] -= b * fb(num[pos] - i * a);
dfs(pos + 1, cnt + i + fb(num[pos] - i * a));
num[pos + 2] += b * fb(num[pos] - i * a);
num[pos + 1] += a * fb(num[pos] - i * a) + i * b;
temp[pos + 1] -= fb(num[pos] - i * a);
temp[pos] -= i;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> num[i];
if (n == 3) {
cout << (tot = max(fb(num[1]), max(fa(num[2]), fb(num[3])))) << endl;
cout << 2;
for (int i = 2; i <= tot; i++) cout << " 2";
cout << endl;
return 0;
}
num[2] -= fb(num[1]) * a;
num[3] -= fb(num[1]) * b;
num[n - 1] -= fb(num[n]) * a;
num[n - 2] -= fb(num[n]) * b;
memset(temp, 0, sizeof(temp));
tot = 5000;
temp[2] = fb(num[1]);
temp[n - 1] = fb(num[n]);
dfs(2, temp[2] + temp[n - 1]);
cout << tot << endl;
int p = 2;
while (ans[p] == 0) p++;
cout << p;
ans[p]--;
while (p < n) {
while (p < n && ans[p] == 0) p++;
if (p >= n) break;
cout << " " << p;
ans[p]--;
}
cout << endl;
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int num[15];
int fa(int x) {
if (x < 0) return 0;
return x / a + 1;
}
int fb(int x) {
if (x < 0) return 0;
return x / b + 1;
}
int ans[15], tot;
int temp[15];
void dfs(int pos, int cnt) {
if (pos == n - 1) {
if (num[pos] >= 0) {
cnt += fa(num[pos]);
temp[pos] += fa(num[pos]);
}
if (cnt < tot) {
tot = cnt;
for (int i = 2; i < n; i++) {
ans[i] = temp[i];
if (ans[i] < 0) cout << '+';
}
}
return;
}
if (num[pos] < 0)
dfs(pos + 1, cnt);
else {
int f = fa(num[pos]);
for (int i = 0; i <= f; i++) {
temp[pos] += i;
temp[pos + 1] += fb(num[pos] - i * a);
num[pos + 1] -= a * fb(num[pos] - i * a) + i * b;
num[pos + 2] -= b * fb(num[pos] - i * a);
dfs(pos + 1, cnt + i + fb(num[pos] - i * a));
num[pos + 2] += b * fb(num[pos] - i * a);
num[pos + 1] += a * fb(num[pos] - i * a) + i * b;
temp[pos + 1] -= fb(num[pos] - i * a);
temp[pos] -= i;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> num[i];
if (n == 3) {
cout << (tot = max(fb(num[1]), max(fa(num[2]), fb(num[3])))) << endl;
cout << 2;
for (int i = 2; i <= tot; i++) cout << " 2";
cout << endl;
return 0;
}
num[2] -= fb(num[1]) * a;
num[3] -= fb(num[1]) * b;
num[n - 1] -= fb(num[n]) * a;
num[n - 2] -= fb(num[n]) * b;
memset(temp, 0, sizeof(temp));
tot = 5000;
temp[2] = fb(num[1]);
temp[n - 1] = fb(num[n]);
dfs(2, temp[2] + temp[n - 1]);
cout << tot << endl;
int p = 2;
while (ans[p] == 0) p++;
cout << p;
ans[p]--;
while (p < n) {
while (p < n && ans[p] == 0) p++;
if (p >= n) break;
cout << " " << p;
ans[p]--;
}
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
vector<long long> v, mq;
long long n, a, b, sz[15], zx = 999999999;
void dfs(long long wz, long long sl) {
if (sl >= zx) {
return;
}
if (wz == n) {
if (sz[n] < 0) {
zx = sl;
v = mq;
}
return;
}
long long sd = max(sz[wz - 1] / b, max(sz[wz] / a, sz[wz + 1] / b)) + 1;
for (int i = 0; i <= sd; i++) {
if (sz[wz - 1] < i * b) {
sz[wz - 1] -= i * b;
sz[wz] -= i * a;
sz[wz + 1] -= i * b;
for (int j = 1; j <= i; j++) {
mq.push_back(wz);
}
dfs(wz + 1, sl + i);
sz[wz - 1] += i * b;
sz[wz] += i * a;
sz[wz + 1] += i * b;
for (int j = 1; j <= i; j++) {
mq.pop_back();
}
}
}
}
int main() {
scanf("%lld%lld%lld", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%lld", &sz[i]);
}
dfs(2, 0);
cout << zx << endl;
for (int i = 0; i < zx; i++) {
printf("%lld ", v[i]);
}
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> v, mq;
long long n, a, b, sz[15], zx = 999999999;
void dfs(long long wz, long long sl) {
if (sl >= zx) {
return;
}
if (wz == n) {
if (sz[n] < 0) {
zx = sl;
v = mq;
}
return;
}
long long sd = max(sz[wz - 1] / b, max(sz[wz] / a, sz[wz + 1] / b)) + 1;
for (int i = 0; i <= sd; i++) {
if (sz[wz - 1] < i * b) {
sz[wz - 1] -= i * b;
sz[wz] -= i * a;
sz[wz + 1] -= i * b;
for (int j = 1; j <= i; j++) {
mq.push_back(wz);
}
dfs(wz + 1, sl + i);
sz[wz - 1] += i * b;
sz[wz] += i * a;
sz[wz + 1] += i * b;
for (int j = 1; j <= i; j++) {
mq.pop_back();
}
}
}
}
int main() {
scanf("%lld%lld%lld", &n, &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%lld", &sz[i]);
}
dfs(2, 0);
cout << zx << endl;
for (int i = 0; i < zx; i++) {
printf("%lld ", v[i]);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
int n, a, b;
int hs[maxn];
int answerCount = 1000 * 1000;
vector<int> answer;
vector<int> throwsNow;
void gen(int f, int t) {
if (f == n - 1) {
if (hs[f] <= 0 && t < answerCount) answerCount = t, answer = throwsNow;
return;
}
int cycleFrom = max(0, (hs[f - 1] + b - 1) / b);
int cycleTo = max(cycleFrom, (hs[f] + a - 1) / a);
if (f == n - 2) {
cycleFrom = max(cycleFrom, (hs[f + 1] + b - 1) / b);
cycleTo = max(cycleTo, (hs[f + 1] + b - 1) / b);
}
for (int i = cycleFrom; i <= cycleTo; i++) {
hs[f - 1] -= i * b;
hs[f] -= i * a;
hs[f + 1] -= i * b;
throwsNow[f] = i;
gen(f + 1, t + i);
throwsNow[f] = 0;
hs[f + 1] += i * b;
hs[f] += i * a;
hs[f - 1] += i * b;
}
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) cin >> hs[i], hs[i]++;
answer.assign(n, 1000);
throwsNow.assign(n, 0);
gen(1, 0);
cout << answerCount << endl;
for (int i = 0; i < answer.size(); i++)
for (int j = 0; j < answer[i]; j++) cout << i + 1 << ' ';
cout << endl;
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
int n, a, b;
int hs[maxn];
int answerCount = 1000 * 1000;
vector<int> answer;
vector<int> throwsNow;
void gen(int f, int t) {
if (f == n - 1) {
if (hs[f] <= 0 && t < answerCount) answerCount = t, answer = throwsNow;
return;
}
int cycleFrom = max(0, (hs[f - 1] + b - 1) / b);
int cycleTo = max(cycleFrom, (hs[f] + a - 1) / a);
if (f == n - 2) {
cycleFrom = max(cycleFrom, (hs[f + 1] + b - 1) / b);
cycleTo = max(cycleTo, (hs[f + 1] + b - 1) / b);
}
for (int i = cycleFrom; i <= cycleTo; i++) {
hs[f - 1] -= i * b;
hs[f] -= i * a;
hs[f + 1] -= i * b;
throwsNow[f] = i;
gen(f + 1, t + i);
throwsNow[f] = 0;
hs[f + 1] += i * b;
hs[f] += i * a;
hs[f - 1] += i * b;
}
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i < n; i++) cin >> hs[i], hs[i]++;
answer.assign(n, 1000);
throwsNow.assign(n, 0);
gen(1, 0);
cout << answerCount << endl;
for (int i = 0; i < answer.size(); i++)
for (int j = 0; j < answer[i]; j++) cout << i + 1 << ' ';
cout << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int f[20][20][20], q[20][20][20], p[20][20][20], xx[20][20][20], yy[20][20][20];
int h[20];
int tot, x, y, z, h1, h2, h3, n, m, a, b, k, j, tot1;
void print(int w, int ii, int jj) {
if (w > 0) print(w - 1, xx[w][ii][jj], yy[w][ii][jj]);
if (w != m) {
for (int i = 1; i <= p[w][ii][jj]; i++) printf("%d ", w + 1);
for (int i = 1; i <= q[w][ii][jj]; i++) printf("%d ", w + 2);
}
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i <= n - 1; i++) {
scanf("%d", &h[i]);
h[i]++;
}
tot = 0;
while (h[0] > 0) {
h[0] -= b;
h[1] -= a;
h[2] -= b;
tot++;
}
h[1] = max(h[1], 0);
h[2] = max(h[2], 0);
k = 0;
while (h[n - 1] > 0) {
h[n - 3] -= b;
h[n - 2] -= a;
h[n - 1] -= b;
tot1++;
}
h[n - 1] = 0;
h[n - 2] = max(h[n - 2], 0);
h[n - 3] = max(h[n - 3], 0);
if (tot1 == 0) {
cout << tot << endl;
for (int i = 1; i < tot; i++) printf("2 ");
printf("2\n");
} else {
m = n - 2;
f[0][h[1]][h[2]] = tot;
q[0][h[1]][h[2]] = tot;
p[0][h[1]][h[2]] = 0;
for (int i = 1; i <= m; i++) {
x = h[i];
for (; x >= 0; x--) {
y = h[i + 1];
for (; y >= 0; y--) {
if (f[i - 1][x][y] != 0) {
z = h[i + 2];
j = x / a;
if (x % a != 0) j++;
for (; j >= 0; j--) {
h1 = x - j * a;
h2 = y - j * b;
h3 = z;
h1 = max(h1, 0);
h2 = max(h2, 0);
k = h1 / b;
if (h1 % b != 0) k++;
h2 = h2 - k * a;
h3 = h3 - k * b;
h2 = max(h2, 0);
h3 = max(h3, 0);
if (f[i][h2][h3] == 0) {
f[i][h2][h3] = f[i - 1][x][y] + j + k;
p[i][h2][h3] = j;
q[i][h2][h3] = k;
xx[i][h2][h3] = x;
yy[i][h2][h3] = y;
} else if (f[i][h2][h3] > f[i - 1][x][y] + j + k) {
f[i][h2][h3] = f[i - 1][x][y] + j + k;
p[i][h2][h3] = j;
q[i][h2][h3] = k;
xx[i][h2][h3] = x;
yy[i][h2][h3] = y;
}
}
}
}
}
}
cout << f[m][0][0] + tot1 << endl;
print(m, 0, 0);
for (int i = 1; i < tot1; i++) printf("%d ", m + 1);
printf("%d\n", m + 1);
}
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int f[20][20][20], q[20][20][20], p[20][20][20], xx[20][20][20], yy[20][20][20];
int h[20];
int tot, x, y, z, h1, h2, h3, n, m, a, b, k, j, tot1;
void print(int w, int ii, int jj) {
if (w > 0) print(w - 1, xx[w][ii][jj], yy[w][ii][jj]);
if (w != m) {
for (int i = 1; i <= p[w][ii][jj]; i++) printf("%d ", w + 1);
for (int i = 1; i <= q[w][ii][jj]; i++) printf("%d ", w + 2);
}
}
int main() {
cin >> n >> a >> b;
for (int i = 0; i <= n - 1; i++) {
scanf("%d", &h[i]);
h[i]++;
}
tot = 0;
while (h[0] > 0) {
h[0] -= b;
h[1] -= a;
h[2] -= b;
tot++;
}
h[1] = max(h[1], 0);
h[2] = max(h[2], 0);
k = 0;
while (h[n - 1] > 0) {
h[n - 3] -= b;
h[n - 2] -= a;
h[n - 1] -= b;
tot1++;
}
h[n - 1] = 0;
h[n - 2] = max(h[n - 2], 0);
h[n - 3] = max(h[n - 3], 0);
if (tot1 == 0) {
cout << tot << endl;
for (int i = 1; i < tot; i++) printf("2 ");
printf("2\n");
} else {
m = n - 2;
f[0][h[1]][h[2]] = tot;
q[0][h[1]][h[2]] = tot;
p[0][h[1]][h[2]] = 0;
for (int i = 1; i <= m; i++) {
x = h[i];
for (; x >= 0; x--) {
y = h[i + 1];
for (; y >= 0; y--) {
if (f[i - 1][x][y] != 0) {
z = h[i + 2];
j = x / a;
if (x % a != 0) j++;
for (; j >= 0; j--) {
h1 = x - j * a;
h2 = y - j * b;
h3 = z;
h1 = max(h1, 0);
h2 = max(h2, 0);
k = h1 / b;
if (h1 % b != 0) k++;
h2 = h2 - k * a;
h3 = h3 - k * b;
h2 = max(h2, 0);
h3 = max(h3, 0);
if (f[i][h2][h3] == 0) {
f[i][h2][h3] = f[i - 1][x][y] + j + k;
p[i][h2][h3] = j;
q[i][h2][h3] = k;
xx[i][h2][h3] = x;
yy[i][h2][h3] = y;
} else if (f[i][h2][h3] > f[i - 1][x][y] + j + k) {
f[i][h2][h3] = f[i - 1][x][y] + j + k;
p[i][h2][h3] = j;
q[i][h2][h3] = k;
xx[i][h2][h3] = x;
yy[i][h2][h3] = y;
}
}
}
}
}
}
cout << f[m][0][0] + tot1 << endl;
print(m, 0, 0);
for (int i = 1; i < tot1; i++) printf("%d ", m + 1);
printf("%d\n", m + 1);
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
const int inf = 1e9;
int dp[maxn][maxn][maxn];
int vis[maxn][maxn][maxn];
int path[maxn][maxn][maxn];
int n, a, b;
int h[maxn];
int dfs(int i, int cur, int pre) {
cur = cur < 0 ? 0 : cur;
pre = pre < 0 ? 0 : pre;
if (i == n) {
if (cur == 0)
return 0;
else
return inf;
}
if (vis[i][cur][pre]) return dp[i][cur][pre];
vis[i][cur][pre] = 1;
int &ans = dp[i][cur][pre];
ans = inf;
int lb = (pre + b - 1) / b,
hb = max(lb, max((cur + a - 1) / a, (h[i + 1] + b) / b));
int p;
for (int j = lb; j <= hb; j++) {
int tmp = j + dfs(i + 1, h[i + 1] + 1 - j * b, cur - j * a);
if (ans > tmp) {
ans = tmp;
path[i][cur][pre] = j;
}
}
return ans;
}
void print(int i, int cur, int pre) {
cur = cur < 0 ? 0 : cur;
pre = pre < 0 ? 0 : pre;
if (i == n) return;
int tmp = path[i][cur][pre], cnt = tmp;
while (cnt--) printf("%d ", i);
print(i + 1, h[i + 1] + 1 - tmp * b, cur - tmp * a);
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
memset(vis, 0, sizeof(vis));
int ans = dfs(2, h[2] + 1, h[1] + 1);
cout << ans << "\n";
print(2, h[2] + 1, h[1] + 1);
puts("");
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
const int inf = 1e9;
int dp[maxn][maxn][maxn];
int vis[maxn][maxn][maxn];
int path[maxn][maxn][maxn];
int n, a, b;
int h[maxn];
int dfs(int i, int cur, int pre) {
cur = cur < 0 ? 0 : cur;
pre = pre < 0 ? 0 : pre;
if (i == n) {
if (cur == 0)
return 0;
else
return inf;
}
if (vis[i][cur][pre]) return dp[i][cur][pre];
vis[i][cur][pre] = 1;
int &ans = dp[i][cur][pre];
ans = inf;
int lb = (pre + b - 1) / b,
hb = max(lb, max((cur + a - 1) / a, (h[i + 1] + b) / b));
int p;
for (int j = lb; j <= hb; j++) {
int tmp = j + dfs(i + 1, h[i + 1] + 1 - j * b, cur - j * a);
if (ans > tmp) {
ans = tmp;
path[i][cur][pre] = j;
}
}
return ans;
}
void print(int i, int cur, int pre) {
cur = cur < 0 ? 0 : cur;
pre = pre < 0 ? 0 : pre;
if (i == n) return;
int tmp = path[i][cur][pre], cnt = tmp;
while (cnt--) printf("%d ", i);
print(i + 1, h[i + 1] + 1 - tmp * b, cur - tmp * a);
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> h[i];
memset(vis, 0, sizeof(vis));
int ans = dfs(2, h[2] + 1, h[1] + 1);
cout << ans << "\n";
print(2, h[2] + 1, h[1] + 1);
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 15, INF = 0x3f3f3f3f;
int n, h[N], mx = INF, a, b;
vector<int> ans, t;
void dfs(int i, int cnt) {
if (cnt >= mx) return;
if (i == n) {
if (h[n] < 0 && cnt < mx) {
ans = t;
mx = cnt;
}
return;
}
int k = max(h[i - 1] / b + 1, max(h[i] / a + 1, h[i + 1] / b + 1));
for (int j = 0; j <= k; j++)
if (h[i - 1] < j * b) {
h[i - 1] -= j * b;
h[i + 1] -= j * b;
h[i] -= j * a;
for (int x = 0; x < j; x++) t.push_back(i);
dfs(i + 1, cnt + j);
h[i - 1] += j * b;
h[i + 1] += j * b;
h[i] += j * a;
for (int x = 0; x < j; x++) t.pop_back();
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
dfs(2, 0);
printf("%d\n", mx);
for (int i = 0; i < mx; i++) printf("%d ", ans[i]);
puts("");
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 15, INF = 0x3f3f3f3f;
int n, h[N], mx = INF, a, b;
vector<int> ans, t;
void dfs(int i, int cnt) {
if (cnt >= mx) return;
if (i == n) {
if (h[n] < 0 && cnt < mx) {
ans = t;
mx = cnt;
}
return;
}
int k = max(h[i - 1] / b + 1, max(h[i] / a + 1, h[i + 1] / b + 1));
for (int j = 0; j <= k; j++)
if (h[i - 1] < j * b) {
h[i - 1] -= j * b;
h[i + 1] -= j * b;
h[i] -= j * a;
for (int x = 0; x < j; x++) t.push_back(i);
dfs(i + 1, cnt + j);
h[i - 1] += j * b;
h[i + 1] += j * b;
h[i] += j * a;
for (int x = 0; x < j; x++) t.pop_back();
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
dfs(2, 0);
printf("%d\n", mx);
for (int i = 0; i < mx; i++) printf("%d ", ans[i]);
puts("");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[20];
int tans = 100000;
vector<int> ans1, ans;
void Dfs(int p, int tm) {
if (tm >= tans) return;
if (p == n) {
if (h[n] < 0) {
ans = ans1;
tans = tm;
}
return;
}
for (int i = max(0, h[p - 1] / b);
i <= max(h[p - 1] / b + 1, max(h[p] / a + 1, h[p + 1] / b + 1)); i++) {
if (h[p - 1] < b * i) {
h[p - 1] -= i * b, h[p] -= i * a, h[p + 1] -= i * b;
for (int j = 1; j <= i; j++) ans1.push_back(p);
Dfs(p + 1, tm + i);
for (int j = 1; j <= i; j++) ans1.pop_back();
h[p - 1] += i * b, h[p] += i * a, h[p + 1] += i * b;
}
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
Dfs(2, 0);
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[20];
int tans = 100000;
vector<int> ans1, ans;
void Dfs(int p, int tm) {
if (tm >= tans) return;
if (p == n) {
if (h[n] < 0) {
ans = ans1;
tans = tm;
}
return;
}
for (int i = max(0, h[p - 1] / b);
i <= max(h[p - 1] / b + 1, max(h[p] / a + 1, h[p + 1] / b + 1)); i++) {
if (h[p - 1] < b * i) {
h[p - 1] -= i * b, h[p] -= i * a, h[p + 1] -= i * b;
for (int j = 1; j <= i; j++) ans1.push_back(p);
Dfs(p + 1, tm + i);
for (int j = 1; j <= i; j++) ans1.pop_back();
h[p - 1] += i * b, h[p] += i * a, h[p + 1] += i * b;
}
}
}
int main() {
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
Dfs(2, 0);
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1);
namespace {
template <typename T>
inline void read(T &x) {
x = 0;
T f = 1;
char s = getchar();
for (; !isdigit(s); s = getchar())
if (s == '-') f = -1;
for (; isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
x *= f;
}
} // namespace
int n, a, b, sum = 999999;
int e[11];
vector<int> ve, anve;
void dfs(int step, int ans) {
if (ans >= sum) return;
if (n == step) {
if (e[n] < 0 && ans < sum) {
sum = ans;
anve = ve;
}
return;
}
int Max = max(e[step - 1] / b, max(e[step] / a, e[step + 1] / b)) + 1;
for (int i = 0; i <= Max; i++) {
if (e[step - 1] - i * b < 0) {
e[step - 1] -= i * b;
e[step] -= i * a;
e[step + 1] -= i * b;
for (register int j = (0); j < (i); ++j) ve.push_back(step);
dfs(step + 1, ans + i);
for (register int j = (0); j < (i); ++j) ve.pop_back();
e[step - 1] += i * b;
e[step] += i * a;
e[step + 1] += i * b;
}
}
}
int main() {
cin >> n >> a >> b;
for (register int i = (1); i <= (n); ++i) cin >> e[i];
dfs(2, 0);
cout << sum << endl;
for (register int i = (0); i < (anve.size()); ++i) cout << anve[i] << " ";
}
|
### Prompt
Generate a cpp solution to the following problem:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1);
namespace {
template <typename T>
inline void read(T &x) {
x = 0;
T f = 1;
char s = getchar();
for (; !isdigit(s); s = getchar())
if (s == '-') f = -1;
for (; isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
x *= f;
}
} // namespace
int n, a, b, sum = 999999;
int e[11];
vector<int> ve, anve;
void dfs(int step, int ans) {
if (ans >= sum) return;
if (n == step) {
if (e[n] < 0 && ans < sum) {
sum = ans;
anve = ve;
}
return;
}
int Max = max(e[step - 1] / b, max(e[step] / a, e[step + 1] / b)) + 1;
for (int i = 0; i <= Max; i++) {
if (e[step - 1] - i * b < 0) {
e[step - 1] -= i * b;
e[step] -= i * a;
e[step + 1] -= i * b;
for (register int j = (0); j < (i); ++j) ve.push_back(step);
dfs(step + 1, ans + i);
for (register int j = (0); j < (i); ++j) ve.pop_back();
e[step - 1] += i * b;
e[step] += i * a;
e[step + 1] += i * b;
}
}
}
int main() {
cin >> n >> a >> b;
for (register int i = (1); i <= (n); ++i) cin >> e[i];
dfs(2, 0);
cout << sum << endl;
for (register int i = (0); i < (anve.size()); ++i) cout << anve[i] << " ";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[15];
int best_fireball = 1e6;
int best_ans[15];
int cur_fireball = 0;
int cur_ans[15];
void solve(int id) {
if (cur_fireball > 100) {
return;
}
if (id == n) {
if (h[n - 1] >= 0 || h[n] >= 0) return;
if (cur_fireball < best_fireball) {
best_fireball = cur_fireball;
for (int i = 1; i <= n; i++) {
best_ans[i] = cur_ans[i];
}
}
return;
}
int most = 0;
most = max(most, (h[id - 1] + b) / b);
most = max(most, (h[id] + a) / a);
most = max(most, (h[id + 1] + b) / b);
if (id != 2 && id != n - 1) most = min(most, 8);
for (int i = 0; i <= most; i++) {
h[id - 1] -= b * i;
h[id] -= a * i;
h[id + 1] -= b * i;
if (h[id - 1] < 0) {
cur_fireball += i;
cur_ans[id] = i;
solve(id + 1);
cur_fireball -= i;
}
h[id - 1] += b * i;
h[id] += a * i;
h[id + 1] += b * i;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
solve(2);
cout << best_fireball << "\n";
for (int i = 1; i <= n; i++) {
for (int j = 0; j < best_ans[i]; j++) {
cout << i << " ";
}
}
cout << "\n";
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int h[15];
int best_fireball = 1e6;
int best_ans[15];
int cur_fireball = 0;
int cur_ans[15];
void solve(int id) {
if (cur_fireball > 100) {
return;
}
if (id == n) {
if (h[n - 1] >= 0 || h[n] >= 0) return;
if (cur_fireball < best_fireball) {
best_fireball = cur_fireball;
for (int i = 1; i <= n; i++) {
best_ans[i] = cur_ans[i];
}
}
return;
}
int most = 0;
most = max(most, (h[id - 1] + b) / b);
most = max(most, (h[id] + a) / a);
most = max(most, (h[id + 1] + b) / b);
if (id != 2 && id != n - 1) most = min(most, 8);
for (int i = 0; i <= most; i++) {
h[id - 1] -= b * i;
h[id] -= a * i;
h[id + 1] -= b * i;
if (h[id - 1] < 0) {
cur_fireball += i;
cur_ans[id] = i;
solve(id + 1);
cur_fireball -= i;
}
h[id - 1] += b * i;
h[id] += a * i;
h[id + 1] += b * i;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
solve(2);
cout << best_fireball << "\n";
for (int i = 1; i <= n; i++) {
for (int j = 0; j < best_ans[i]; j++) {
cout << i << " ";
}
}
cout << "\n";
return 0;
}
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.