output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, h1, h2;
cin >> h1 >> h2 >> a >> b;
if (h2 <= h1 + 8 * a)
cout << 0 << endl;
else {
if (a <= b)
cout << -1 << endl;
else {
int j = h1 - 12 * b + 8 * a;
int count = 0;
while (true) {
count++;
j += 12 * a;
if (j >= h2) {
cout << count << endl;
return 0;
}
j -= 12 * b;
}
}
}
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, h1, h2;
cin >> h1 >> h2 >> a >> b;
if (h2 <= h1 + 8 * a)
cout << 0 << endl;
else {
if (a <= b)
cout << -1 << endl;
else {
int j = h1 - 12 * b + 8 * a;
int count = 0;
while (true) {
count++;
j += 12 * a;
if (j >= h2) {
cout << count << endl;
return 0;
}
j -= 12 * b;
}
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int h, h1, h2, c, c1, c2, ans = 0;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &c1, &c2);
c = c1 - c2;
h = h2 - h1;
if (c1 <= c2 && c1 * 8 < h) {
ans = -1;
} else if (c1 * 8 >= h) {
ans = 0;
} else if (c1 > c2) {
h = h - 20 * c1 + c2 * 12;
ans++;
while (h > 0) {
h -= 12 * c;
ans++;
}
}
printf("%d", ans);
}
|
### Prompt
Please create a solution in cpp to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int h, h1, h2, c, c1, c2, ans = 0;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &c1, &c2);
c = c1 - c2;
h = h2 - h1;
if (c1 <= c2 && c1 * 8 < h) {
ans = -1;
} else if (c1 * 8 >= h) {
ans = 0;
} else if (c1 > c2) {
h = h - 20 * c1 + c2 * 12;
ans++;
while (h > 0) {
h -= 12 * c;
ans++;
}
}
printf("%d", ans);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int ans;
int main() {
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
h2 -= h1 + 8 * a;
a = (a - b) * 12;
if (h2 <= 0)
printf("0\n");
else if (a <= 0)
printf("-1\n");
else
printf("%d\n", (h2 + a - 1) / a);
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int ans;
int main() {
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
h2 -= h1 + 8 * a;
a = (a - b) * 12;
if (h2 <= 0)
printf("0\n");
else if (a <= 0)
printf("-1\n");
else
printf("%d\n", (h2 + a - 1) / a);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
int h1, h2;
cin >> h1 >> h2;
cin >> a >> b;
if (((h2 - h1) / (float)a) <= 8) {
cout << 0 << endl;
} else {
if (a <= b) {
cout << -1 << endl;
} else {
cout << ceil((h2 - h1 - a * 8.0) / (a - b) / 12) << endl;
}
}
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
int h1, h2;
cin >> h1 >> h2;
cin >> a >> b;
if (((h2 - h1) / (float)a) <= 8) {
cout << 0 << endl;
} else {
if (a <= b) {
cout << -1 << endl;
} else {
cout << ceil((h2 - h1 - a * 8.0) / (a - b) / 12) << endl;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
if (b >= a) {
h1 += 8 * a;
if (h1 >= h2)
printf("0\n");
else
printf("-1\n");
return 0;
} else {
int d = 0;
h1 += 8 * a;
if (h1 >= h2) {
printf("0\n");
return 0;
} else {
h1 -= 12 * b;
}
d += 1;
while (h1 < h2) {
d++;
h1 += 12 * a;
if (h1 >= h2) {
printf("%d", d - 1);
return 0;
}
h1 -= 12 * b;
}
}
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
if (b >= a) {
h1 += 8 * a;
if (h1 >= h2)
printf("0\n");
else
printf("-1\n");
return 0;
} else {
int d = 0;
h1 += 8 * a;
if (h1 >= h2) {
printf("0\n");
return 0;
} else {
h1 -= 12 * b;
}
d += 1;
while (h1 < h2) {
d++;
h1 += 12 * a;
if (h1 >= h2) {
printf("%d", d - 1);
return 0;
}
h1 -= 12 * b;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
typedef int *arrint;
const int maxn = 2e3 + 55;
int main() {
int h1, h2, a, b, i, j, k;
scanf("%d", &h1), scanf("%d", &h2);
scanf("%d", &a), scanf("%d", &b);
k = 0;
i = h1;
j = 1;
while (i < h2) {
if (j == 1) {
i = i + a * 8;
j = 0;
if (a <= b && i < h2) {
k = -1;
break;
}
} else {
i = i + a * 12;
}
if (i >= h2) {
break;
} else {
k++;
i -= b * 12;
}
}
printf("%d", k), printf("%c", '\n');
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef int *arrint;
const int maxn = 2e3 + 55;
int main() {
int h1, h2, a, b, i, j, k;
scanf("%d", &h1), scanf("%d", &h2);
scanf("%d", &a), scanf("%d", &b);
k = 0;
i = h1;
j = 1;
while (i < h2) {
if (j == 1) {
i = i + a * 8;
j = 0;
if (a <= b && i < h2) {
k = -1;
break;
}
} else {
i = i + a * 12;
}
if (i >= h2) {
break;
} else {
k++;
i -= b * 12;
}
}
printf("%d", k), printf("%c", '\n');
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long h1, h2;
cin >> h1 >> h2;
long long a, b;
cin >> a >> b;
if (8 * a + h1 >= h2) {
puts("0");
return 0;
}
h1 += 8 * a;
int counter = 0;
while (h1 < h2 && counter < 1000000) {
h1 += a * 12;
h1 -= b * 12;
counter++;
}
if (h1 < h2)
puts("-1");
else
cout << counter << '\n';
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long h1, h2;
cin >> h1 >> h2;
long long a, b;
cin >> a >> b;
if (8 * a + h1 >= h2) {
puts("0");
return 0;
}
h1 += 8 * a;
int counter = 0;
while (h1 < h2 && counter < 1000000) {
h1 += a * 12;
h1 -= b * 12;
counter++;
}
if (h1 < h2)
puts("-1");
else
cout << counter << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int a, b, c, d, e = 0, f, g, h;
cin >> a >> b >> c >> d;
h = a;
a += 8 * c;
while (a < b) {
e++;
a -= 12 * d;
a += 12 * c;
if (a <= h) {
e = -1;
break;
}
h = a;
}
cout << e << "\n";
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int a, b, c, d, e = 0, f, g, h;
cin >> a >> b >> c >> d;
h = a;
a += 8 * c;
while (a < b) {
e++;
a -= 12 * d;
a += 12 * c;
if (a <= h) {
e = -1;
break;
}
h = a;
}
cout << e << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int m, n, tmp, q, ans, i, j, t, h1, h2, a, b;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("inp.txt", "r")) freopen("inp.txt", "r", stdin);
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2) {
cout << "0\n";
return 0;
}
if (b >= a) {
cout << "-1\n";
return 0;
}
long long int t = (h2 - h1 - 1) / (12 * (a - b));
cout << t + 1;
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int m, n, tmp, q, ans, i, j, t, h1, h2, a, b;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("inp.txt", "r")) freopen("inp.txt", "r", stdin);
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2) {
cout << "0\n";
return 0;
}
if (b >= a) {
cout << "-1\n";
return 0;
}
long long int t = (h2 - h1 - 1) / (12 * (a - b));
cout << t + 1;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
h1 += a * 8;
a -= b;
if (h1 >= h2) {
cout << 0;
return 0;
}
if (a <= 0) {
cout << -1;
return 0;
}
a *= 12;
cout << (h2 - h1 + a - 1) / a;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
h1 += a * 8;
a -= b;
if (h1 >= h2) {
cout << 0;
return 0;
}
if (a <= 0) {
cout << -1;
return 0;
}
a *= 12;
cout << (h2 - h1 + a - 1) / a;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long fac[1000001];
void powe(long long p) {
fac[0] = 1;
for (long long i = 1; i <= 1000000; i++) fac[i] = (fac[i - 1] * i) % p;
}
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long nCrModPFermat(long long n, long long r, long long p) {
if (r == 0) return 1;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long days = 0;
a += (8 * c);
if (a >= b) {
cout << 0 << endl;
return 0;
}
if (c <= d && a < b) {
cout << -1 << endl;
return 0;
}
a -= (12 * d);
days = 1;
while (1) {
a += (12 * c);
if (a >= b) {
cout << days << endl;
return 0;
}
a -= (12 * d);
days++;
}
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long fac[1000001];
void powe(long long p) {
fac[0] = 1;
for (long long i = 1; i <= 1000000; i++) fac[i] = (fac[i - 1] * i) % p;
}
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long nCrModPFermat(long long n, long long r, long long p) {
if (r == 0) return 1;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long days = 0;
a += (8 * c);
if (a >= b) {
cout << 0 << endl;
return 0;
}
if (c <= d && a < b) {
cout << -1 << endl;
return 0;
}
a -= (12 * d);
days = 1;
while (1) {
a += (12 * c);
if (a >= b) {
cout << days << endl;
return 0;
}
a -= (12 * d);
days++;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
while (cin >> h1 >> h2 >> a >> b) {
int dis = h2 - h1;
int day = 0;
if (b > a && dis > (a * 8)) {
cout << -1 << endl;
continue;
} else if (a == b && (dis > (a * 8))) {
cout << -1 << endl;
continue;
}
while (1) {
h1 += (a * 8);
if (h1 >= h2) break;
day++;
h1 -= (b * 12);
h1 += (a * 4);
}
cout << day << endl;
}
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
while (cin >> h1 >> h2 >> a >> b) {
int dis = h2 - h1;
int day = 0;
if (b > a && dis > (a * 8)) {
cout << -1 << endl;
continue;
} else if (a == b && (dis > (a * 8))) {
cout << -1 << endl;
continue;
}
while (1) {
h1 += (a * 8);
if (h1 >= h2) break;
day++;
h1 -= (b * 12);
h1 += (a * 4);
}
cout << day << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h2 - h1 <= 8 * a) {
cout << 0 << endl;
} else if (b >= a) {
cout << -1 << endl;
} else {
bool divisible = (h2 - h1 - 8 * a) % (12 * a - 12 * b) == 0;
cout << (h2 - h1 - 8 * a) / ((a - b) * 12) + ((divisible) ? 0 : 1) << endl;
}
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h2 - h1 <= 8 * a) {
cout << 0 << endl;
} else if (b >= a) {
cout << -1 << endl;
} else {
bool divisible = (h2 - h1 - 8 * a) % (12 * a - 12 * b) == 0;
cout << (h2 - h1 - 8 * a) / ((a - b) * 12) + ((divisible) ? 0 : 1) << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int h1, h2, a, b, cnt = 0;
scanf("%I64d %I64d", &h1, &h2);
scanf("%I64d %I64d", &a, &b);
if (a <= b) {
h1 = (8 * a + h1);
if (h1 >= h2)
printf("0\n");
else
printf("-1");
return 0;
}
h1 = (8 * a + h1);
while (h1 <= h2) {
if (h1 >= h2) break;
h1 -= (12 * b);
cnt++;
h1 += (12 * a);
}
printf("%I64d\n", cnt);
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int h1, h2, a, b, cnt = 0;
scanf("%I64d %I64d", &h1, &h2);
scanf("%I64d %I64d", &a, &b);
if (a <= b) {
h1 = (8 * a + h1);
if (h1 >= h2)
printf("0\n");
else
printf("-1");
return 0;
}
h1 = (8 * a + h1);
while (h1 <= h2) {
if (h1 >= h2) break;
h1 -= (12 * b);
cnt++;
h1 += (12 * a);
}
printf("%I64d\n", cnt);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long h1, h2, a, b;
bool flag;
int main() {
cin >> h1 >> h2 >> a >> b;
for (int i = 0; i <= 200000; ++i) {
if (i == 0)
h1 += 8 * a;
else
h1 += 12 * a;
if (h1 >= h2) {
printf("%d\n", i);
flag = true;
break;
}
h1 -= 12 * b;
}
if (!flag) printf("-1\n");
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long h1, h2, a, b;
bool flag;
int main() {
cin >> h1 >> h2 >> a >> b;
for (int i = 0; i <= 200000; ++i) {
if (i == 0)
h1 += 8 * a;
else
h1 += 12 * a;
if (h1 >= h2) {
printf("%d\n", i);
flag = true;
break;
}
h1 -= 12 * b;
}
if (!flag) printf("-1\n");
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
ios_base::sync_with_stdio(false);
int a, b, c, d;
cin >> a >> b >> c >> d;
b = b - (a + c * 8);
c = (c - d) * 12;
if (b <= 0)
cout << 0 << endl;
else if (c <= 0)
cout << -1 << endl;
else
cout << (b + c - 1) / c << endl;
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
ios_base::sync_with_stdio(false);
int a, b, c, d;
cin >> a >> b >> c >> d;
b = b - (a + c * 8);
c = (c - d) * 12;
if (b <= 0)
cout << 0 << endl;
else if (c <= 0)
cout << -1 << endl;
else
cout << (b + c - 1) / c << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int h1, h2, a, b, day = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
h1 = h1 + 8 * a;
if (h1 >= h2) {
printf("0\n");
} else if (a <= b) {
printf("-1\n");
} else {
while (h1 < h2) {
h1 += (a - b) * 12;
day++;
}
printf("%d\n", day);
}
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int h1, h2, a, b, day = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
h1 = h1 + 8 * a;
if (h1 >= h2) {
printf("0\n");
} else if (a <= b) {
printf("-1\n");
} else {
while (h1 < h2) {
h1 += (a - b) * 12;
day++;
}
printf("%d\n", day);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int MAXN = 1e5 + 1;
int main() {
int x, y;
scanf("%d", &x);
scanf("%d", &y);
int diff = y - x;
int a, b;
scanf("%d", &a);
scanf("%d", &b);
if (b >= a && 8 * a < diff) {
printf("-1\n");
} else {
int day;
int cov = 8 * a;
if (cov >= diff) {
printf("0\n");
return 0;
}
cov -= 12 * b;
for (day = 1;; ++day) {
if ((cov + 12 * a) >= diff) {
break;
}
cov = cov + 12 * (a - b);
}
printf("%d\n", day);
}
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int MAXN = 1e5 + 1;
int main() {
int x, y;
scanf("%d", &x);
scanf("%d", &y);
int diff = y - x;
int a, b;
scanf("%d", &a);
scanf("%d", &b);
if (b >= a && 8 * a < diff) {
printf("-1\n");
} else {
int day;
int cov = 8 * a;
if (cov >= diff) {
printf("0\n");
return 0;
}
cov -= 12 * b;
for (day = 1;; ++day) {
if ((cov + 12 * a) >= diff) {
break;
}
cov = cov + 12 * (a - b);
}
printf("%d\n", day);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int main() {
cin >> h1 >> h2;
cin >> a >> b;
h1 += 8 * a;
if (h1 >= h2) {
cout << 0;
return 0;
}
if (a <= b) {
cout << -1;
return 0;
}
int cnt = 0;
while (true) {
cnt++;
h1 -= 12 * b;
h1 += 12 * a;
if (h1 >= h2) {
cout << cnt;
return 0;
}
}
}
|
### Prompt
Create a solution in cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int main() {
cin >> h1 >> h2;
cin >> a >> b;
h1 += 8 * a;
if (h1 >= h2) {
cout << 0;
return 0;
}
if (a <= b) {
cout << -1;
return 0;
}
int cnt = 0;
while (true) {
cnt++;
h1 -= 12 * b;
h1 += 12 * a;
if (h1 >= h2) {
cout << cnt;
return 0;
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &a, &b);
int ret = 0;
if (a <= b) {
if (h2 - h1 > 8 * a)
puts("-1");
else
puts("0");
} else {
h1 += 8 * a;
while (h1 < h2) {
h1 = h1 - 12 * b;
h1 += 12 * a;
ret++;
}
printf("%d\n", ret);
}
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &a, &b);
int ret = 0;
if (a <= b) {
if (h2 - h1 > 8 * a)
puts("-1");
else
puts("0");
} else {
h1 += 8 * a;
while (h1 < h2) {
h1 = h1 - 12 * b;
h1 += 12 * a;
ret++;
}
printf("%d\n", ret);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b, ans;
const int INF = 10e9;
int main() {
ios_base::sync_with_stdio(false);
cin >> h1 >> h2 >> a >> b;
h1 += (a * 8);
if (h1 >= h2) {
cout << 0;
return 0;
}
h1 -= (b * 12);
if (h1 + (a * 12) < h2 && a <= b) {
cout << -1;
return 0;
}
ans++;
while (h1 + (a * 12) < h2) {
ans++;
h1 += (a * 12);
if (h1 >= h2) {
cout << ans;
return 0;
}
h1 -= (b * 12);
}
cout << ans;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b, ans;
const int INF = 10e9;
int main() {
ios_base::sync_with_stdio(false);
cin >> h1 >> h2 >> a >> b;
h1 += (a * 8);
if (h1 >= h2) {
cout << 0;
return 0;
}
h1 -= (b * 12);
if (h1 + (a * 12) < h2 && a <= b) {
cout << -1;
return 0;
}
ans++;
while (h1 + (a * 12) < h2) {
ans++;
h1 += (a * 12);
if (h1 >= h2) {
cout << ans;
return 0;
}
h1 -= (b * 12);
}
cout << ans;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
h1 += (8 * a);
if (h1 >= h2) {
printf("0\n");
return 0;
}
h1 -= 12 * b;
if (b >= a) {
printf("-1\n");
return 0;
}
for (int i = 1;; i++) {
h1 += 12 * a;
if (h1 >= h2) {
printf("%d\n", i);
return 0;
}
h1 -= 12 * b;
}
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
h1 += (8 * a);
if (h1 >= h2) {
printf("0\n");
return 0;
}
h1 -= 12 * b;
if (b >= a) {
printf("-1\n");
return 0;
}
for (int i = 1;; i++) {
h1 += 12 * a;
if (h1 >= h2) {
printf("%d\n", i);
return 0;
}
h1 -= 12 * b;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2;
int a, b;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> h1 >> h2;
cin >> a >> b;
if (h1 + a * 8 >= h2) {
cout << 0 << '\n';
return 0;
}
if (b >= a) {
cout << -1 << '\n';
return 0;
}
h1 += a * 8;
int res = 0;
while (h1 < h2) {
h1 -= b * 12;
res++;
h1 += a * 12;
}
cout << res << '\n';
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2;
int a, b;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> h1 >> h2;
cin >> a >> b;
if (h1 + a * 8 >= h2) {
cout << 0 << '\n';
return 0;
}
if (b >= a) {
cout << -1 << '\n';
return 0;
}
h1 += a * 8;
int res = 0;
while (h1 < h2) {
h1 -= b * 12;
res++;
h1 += a * 12;
}
cout << res << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> H;
int main() {
int h1, h2, i, d, a, b, flag;
d = 0;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a < h2 && b > a) {
cout << "-1\n";
return 0;
}
flag = 0;
while (h1 < h2) {
H[h1]++;
h1 += 8 * a;
if (h1 >= h2) break;
h1 -= 12 * b;
h1 += 4 * a;
if (h1 >= h2) {
if (h1 > h2) d++;
break;
}
if (H.count(h1) > 0) {
flag = 1;
break;
}
d++;
}
if (flag)
cout << "-1\n";
else
cout << d << "\n";
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> H;
int main() {
int h1, h2, i, d, a, b, flag;
d = 0;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a < h2 && b > a) {
cout << "-1\n";
return 0;
}
flag = 0;
while (h1 < h2) {
H[h1]++;
h1 += 8 * a;
if (h1 >= h2) break;
h1 -= 12 * b;
h1 += 4 * a;
if (h1 >= h2) {
if (h1 > h2) d++;
break;
}
if (H.count(h1) > 0) {
flag = 1;
break;
}
d++;
}
if (flag)
cout << "-1\n";
else
cout << d << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t h1, h2;
cin >> h1 >> h2;
int64_t a, b;
cin >> a >> b;
h1 -= a * 4;
int64_t ans = 0;
while (h1 < h2) {
h1 += a * 4;
if (h1 >= h2) break;
h1 += a * 8;
if (h1 >= h2) break;
h1 -= b * 12;
ans++;
if (ans > 1000000) break;
}
if (h1 < h2) {
cout << -1 << endl;
return 0;
}
cout << ans << endl;
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t h1, h2;
cin >> h1 >> h2;
int64_t a, b;
cin >> a >> b;
h1 -= a * 4;
int64_t ans = 0;
while (h1 < h2) {
h1 += a * 4;
if (h1 >= h2) break;
h1 += a * 8;
if (h1 >= h2) break;
h1 -= b * 12;
ans++;
if (ans > 1000000) break;
}
if (h1 < h2) {
cout << -1 << endl;
return 0;
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
while (cin >> h1 >> h2) {
int a, b;
cin >> a >> b;
int n = (a - b) * 12;
if (n <= 0 && 8 * a + h1 < h2) {
cout << "-1" << endl;
} else {
int j;
if (h2 - h1 <= 8 * a)
j = 0;
else {
int i = h2 - h1 - 8 * a;
for (j = 0; i > 0; j++) i = i - n;
}
cout << j << endl;
}
}
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
while (cin >> h1 >> h2) {
int a, b;
cin >> a >> b;
int n = (a - b) * 12;
if (n <= 0 && 8 * a + h1 < h2) {
cout << "-1" << endl;
} else {
int j;
if (h2 - h1 <= 8 * a)
j = 0;
else {
int i = h2 - h1 - 8 * a;
for (j = 0; i > 0; j++) i = i - n;
}
cout << j << endl;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k, l;
cin >> n >> m >> k >> l;
n = m - n;
if (n <= k * 8) {
cout << "0";
} else {
if (l >= k) {
cout << "-1";
} else {
n = n - k * 8;
m = n / ((k - l) * 12);
l = n % ((k - l) * 12);
m++;
if (l == 0) {
m--;
}
cout << m;
}
}
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k, l;
cin >> n >> m >> k >> l;
n = m - n;
if (n <= k * 8) {
cout << "0";
} else {
if (l >= k) {
cout << "-1";
} else {
n = n - k * 8;
m = n / ((k - l) * 12);
l = n % ((k - l) * 12);
m++;
if (l == 0) {
m--;
}
cout << m;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) {
cout << 0 << endl;
return 0;
}
if (a <= b) {
cout << -1 << endl;
return 0;
}
cout << (h2 - h1 - 8 * a - 1) / (12 * (a - b)) + 1 << endl;
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) {
cout << 0 << endl;
return 0;
}
if (a <= b) {
cout << -1 << endl;
return 0;
}
cout << (h2 - h1 - 8 * a - 1) / (12 * (a - b)) + 1 << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int now, aim;
int sun, moon;
int day = 0;
cin >> now >> aim;
cin >> sun >> moon;
if (now + 8 * sun >= aim) {
cout << day << endl;
} else {
if (moon >= sun) {
cout << "-1" << endl;
} else {
aim = aim - now - 8 * sun;
if (aim % (12 * (sun - moon)) == 0) {
day = aim / (12 * (sun - moon));
} else {
day = aim / (12 * (sun - moon)) + 1;
}
cout << day << endl;
}
}
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int now, aim;
int sun, moon;
int day = 0;
cin >> now >> aim;
cin >> sun >> moon;
if (now + 8 * sun >= aim) {
cout << day << endl;
} else {
if (moon >= sun) {
cout << "-1" << endl;
} else {
aim = aim - now - 8 * sun;
if (aim % (12 * (sun - moon)) == 0) {
day = aim / (12 * (sun - moon));
} else {
day = aim / (12 * (sun - moon)) + 1;
}
cout << day << endl;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
if (a <= b && h1 + a * 8 < h2) return 0 * printf("-1\n");
int ans = 0;
while (h1 + a * 8 < h2) {
ans++;
h1 += (a - b) * 12;
}
printf("%d\n", ans);
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
if (a <= b && h1 + a * 8 < h2) return 0 * printf("-1\n");
int ans = 0;
while (h1 + a * 8 < h2) {
ans++;
h1 += (a - b) * 12;
}
printf("%d\n", ans);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
while (cin >> h1 >> h2) {
cin >> a >> b;
h1 += 8 * a;
if (h1 < h2 && a <= b)
cout << -1 << endl;
else {
int ans = 0;
while (1) {
if (h1 >= h2) {
cout << ans << endl;
break;
}
h1 -= 12 * b;
h1 += 12 * a;
ans++;
}
}
}
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
while (cin >> h1 >> h2) {
cin >> a >> b;
h1 += 8 * a;
if (h1 < h2 && a <= b)
cout << -1 << endl;
else {
int ans = 0;
while (1) {
if (h1 >= h2) {
cout << ans << endl;
break;
}
h1 -= 12 * b;
h1 += 12 * a;
ans++;
}
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t = 1;
while (t--) solve();
return 0;
}
void solve() {
long long int i, j, cnt = 0;
bool flag = 0;
long long int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) {
cout << 0 << "\n";
} else if (a <= b) {
cout << -1 << "\n";
} else {
long long int day = 1;
h1 += (8 * a - 12 * b);
while (h1 < h2) {
h1 += 12 * a;
if (h1 >= h2) {
break;
}
h1 -= 12 * b;
day++;
}
cout << day << "\n";
}
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve();
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t = 1;
while (t--) solve();
return 0;
}
void solve() {
long long int i, j, cnt = 0;
bool flag = 0;
long long int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) {
cout << 0 << "\n";
} else if (a <= b) {
cout << -1 << "\n";
} else {
long long int day = 1;
h1 += (8 * a - 12 * b);
while (h1 < h2) {
h1 += 12 * a;
if (h1 >= h2) {
break;
}
h1 -= 12 * b;
day++;
}
cout << day << "\n";
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2) {
cout << 0;
return 0;
}
int rate = 12 * a - 12 * b;
if (rate <= 0) {
cout << -1;
return 0;
} else {
if ((h2 - h1) % rate == 0) {
cout << (h2 - h1) / rate;
} else
cout << ((h2 - h1) / rate + 1);
}
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2) {
cout << 0;
return 0;
}
int rate = 12 * a - 12 * b;
if (rate <= 0) {
cout << -1;
return 0;
} else {
if ((h2 - h1) % rate == 0) {
cout << (h2 - h1) / rate;
} else
cout << ((h2 - h1) / rate + 1);
}
return 0;
}
```
|
#include <bits/stdc++.h>
const int inf = (1 << 30) - 10;
using namespace std;
inline int get_int() {
int r = 0;
char c;
while ((c = getchar()) != ' ' && c != '\n') r = r * 10 + c - '0';
return r;
}
inline void out(int x) {
if (x > 10) {
out(x / 10);
}
putchar(x % 10 + '0');
putchar('\n');
}
int main() {
int h, H, u, d, l;
scanf("%d%d%d%d", &h, &H, &u, &d);
l = 0;
if (u <= d) {
}
while (h < H) {
h += 8 * u;
if (h >= H) break;
l++;
h -= 12 * d;
if (u <= d) {
h += 12 * u;
if (h < H) {
l = -1;
break;
}
}
h += 4 * u;
}
printf("%d\n", l);
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
const int inf = (1 << 30) - 10;
using namespace std;
inline int get_int() {
int r = 0;
char c;
while ((c = getchar()) != ' ' && c != '\n') r = r * 10 + c - '0';
return r;
}
inline void out(int x) {
if (x > 10) {
out(x / 10);
}
putchar(x % 10 + '0');
putchar('\n');
}
int main() {
int h, H, u, d, l;
scanf("%d%d%d%d", &h, &H, &u, &d);
l = 0;
if (u <= d) {
}
while (h < H) {
h += 8 * u;
if (h >= H) break;
l++;
h -= 12 * d;
if (u <= d) {
h += 12 * u;
if (h < H) {
l = -1;
break;
}
}
h += 4 * u;
}
printf("%d\n", l);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long h1, h2, v1, v2;
cin >> h1 >> h2;
cin >> v1 >> v2;
int vm = v1 - v2, h = h2 - h1;
if (vm > 0) {
int dias = 0;
while (h >= 0) {
h -= 8 * v1;
if (h <= 0) {
break;
}
h += 12 * v2;
h -= 4 * v1;
dias++;
}
cout << dias << endl;
} else {
if (h - 8 * v1 <= 0)
cout << 0 << endl;
else
cout << -1 << endl;
}
}
|
### Prompt
Please formulate a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long h1, h2, v1, v2;
cin >> h1 >> h2;
cin >> v1 >> v2;
int vm = v1 - v2, h = h2 - h1;
if (vm > 0) {
int dias = 0;
while (h >= 0) {
h -= 8 * v1;
if (h <= 0) {
break;
}
h += 12 * v2;
h -= 4 * v1;
dias++;
}
cout << dias << endl;
} else {
if (h - 8 * v1 <= 0)
cout << 0 << endl;
else
cout << -1 << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long h1, h2;
cin >> h1 >> h2;
long long a, b;
cin >> a >> b;
long long r = 8 * a;
long long v = 12 * b;
long long p = 12 * a - v;
h1 = h1 + r;
if (h1 >= h2)
cout << "0" << endl;
else {
if (a <= b)
cout << "-1" << endl;
else {
long long u = h2 - h1;
long long t = u / p;
if (u % p != 0) t = t + 1;
cout << t << endl;
}
}
}
|
### Prompt
Generate a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long h1, h2;
cin >> h1 >> h2;
long long a, b;
cin >> a >> b;
long long r = 8 * a;
long long v = 12 * b;
long long p = 12 * a - v;
h1 = h1 + r;
if (h1 >= h2)
cout << "0" << endl;
else {
if (a <= b)
cout << "-1" << endl;
else {
long long u = h2 - h1;
long long t = u / p;
if (u % p != 0) t = t + 1;
cout << t << endl;
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, rez = 0;
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2)
cout << "0";
else if (b >= a)
cout << "-1";
else {
while (h1 < h2) {
h1 -= 12 * b;
h1 += 12 * a;
rez++;
}
cout << rez;
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, rez = 0;
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2)
cout << "0";
else if (b >= a)
cout << "-1";
else {
while (h1 < h2) {
h1 -= 12 * b;
h1 += 12 * a;
rez++;
}
cout << rez;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, i = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
if (a < b && h2 > a * 8 + h1)
printf("-1");
else if (a == b && h2 > a * 8 + h1)
printf("-1");
else {
h1 += 8 * a;
while (h1 < h2) {
h1 += a * 12;
h1 -= b * 12;
i++;
}
printf("%d", i);
}
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, i = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
if (a < b && h2 > a * 8 + h1)
printf("-1");
else if (a == b && h2 > a * 8 + h1)
printf("-1");
else {
h1 += 8 * a;
while (h1 < h2) {
h1 += a * 12;
h1 -= b * 12;
i++;
}
printf("%d", i);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long h1, h2, a, b;
cin >> h1 >> h2;
long long d = h2 - h1;
cin >> a >> b;
if (8 * a >= d) return cout << 0, 0;
if (a <= b) return cout << -1, 0;
long long cnt = 0;
d -= 8 * a;
long long turn = 0;
while (d > 0) {
if (!turn)
d += 12 * b;
else
d -= 12 * a;
turn ^= 1;
cnt++;
}
cout << cnt / 2;
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long h1, h2, a, b;
cin >> h1 >> h2;
long long d = h2 - h1;
cin >> a >> b;
if (8 * a >= d) return cout << 0, 0;
if (a <= b) return cout << -1, 0;
long long cnt = 0;
d -= 8 * a;
long long turn = 0;
while (d > 0) {
if (!turn)
d += 12 * b;
else
d -= 12 * a;
turn ^= 1;
cnt++;
}
cout << cnt / 2;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
map<int, vector<pair<int, string> > > m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s, d, a, b;
cin >> s >> d >> a >> b;
d -= s;
d -= a * 8;
if (d <= 0) {
cout << "0";
return 0;
}
a = a * 12 - b * 12;
if (a <= 0) {
cout << "-1";
return 0;
}
if (d % a == 0)
cout << d / a;
else
cout << d / a + 1;
return (0);
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, vector<pair<int, string> > > m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s, d, a, b;
cin >> s >> d >> a >> b;
d -= s;
d -= a * 8;
if (d <= 0) {
cout << "0";
return 0;
}
a = a * 12 - b * 12;
if (a <= 0) {
cout << "-1";
return 0;
}
if (d % a == 0)
cout << d / a;
else
cout << d / a + 1;
return (0);
}
```
|
#include <bits/stdc++.h>
using namespace std;
const long long int N = 100005;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
{
long long int i, j, k, n, m, a, b, ans = 0, cnt = 0, sum = 0;
cin >> n >> m >> a >> b;
if (n + 8 * a >= m) {
cout << "0";
return 0;
} else if (a > b) {
long long int x = m - n - (8 * a);
long long int y = 12 * (a - b);
ans = (x + y - 1) / y;
cout << ans << endl;
} else {
cout << "-1";
}
}
}
|
### Prompt
Please create a solution in cpp to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int N = 100005;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
{
long long int i, j, k, n, m, a, b, ans = 0, cnt = 0, sum = 0;
cin >> n >> m >> a >> b;
if (n + 8 * a >= m) {
cout << "0";
return 0;
} else if (a > b) {
long long int x = m - n - (8 * a);
long long int y = 12 * (a - b);
ans = (x + y - 1) / y;
cout << ans << endl;
} else {
cout << "-1";
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long h1, h2, a, b, x, days;
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2) cout << 0 << endl, exit(0);
if (a <= b) cout << -1 << endl, exit(0);
h1 -= 12 * b;
x = max((h2 - h1 - 12 * a) / (12 * (a - b)), 0LL);
days += x;
h1 += x * 12 * (a - b);
while (1) {
h1 += 12 * a;
++days;
if (h1 >= h2) cout << days << endl, exit(0);
h1 += -12 * b;
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long h1, h2, a, b, x, days;
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 >= h2) cout << 0 << endl, exit(0);
if (a <= b) cout << -1 << endl, exit(0);
h1 -= 12 * b;
x = max((h2 - h1 - 12 * a) / (12 * (a - b)), 0LL);
days += x;
h1 += x * 12 * (a - b);
while (1) {
h1 += 12 * a;
++days;
if (h1 >= h2) cout << days << endl, exit(0);
h1 += -12 * b;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
int count_days = 0;
long long cur_h = h1;
bool reached = false;
for (int iteration = 1; iteration <= 112345; iteration++) {
for (int hour = 14; hour < 22; hour++) {
cur_h += a;
if (cur_h >= 1LL * h2) {
reached = true;
break;
}
}
if (reached) {
break;
}
count_days++;
for (int hour = -2; hour < 10; hour++) {
cur_h -= b;
}
for (int hour = 10; hour < 14; hour++) {
cur_h += a;
if (cur_h >= 1LL * h2) {
reached = true;
break;
}
}
if (reached) {
break;
}
}
if (!reached) {
count_days = -1;
}
printf("%d\n", count_days);
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
int count_days = 0;
long long cur_h = h1;
bool reached = false;
for (int iteration = 1; iteration <= 112345; iteration++) {
for (int hour = 14; hour < 22; hour++) {
cur_h += a;
if (cur_h >= 1LL * h2) {
reached = true;
break;
}
}
if (reached) {
break;
}
count_days++;
for (int hour = -2; hour < 10; hour++) {
cur_h -= b;
}
for (int hour = 10; hour < 14; hour++) {
cur_h += a;
if (cur_h >= 1LL * h2) {
reached = true;
break;
}
}
if (reached) {
break;
}
}
if (!reached) {
count_days = -1;
}
printf("%d\n", count_days);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b, count;
count = 0;
cin >> h1 >> h2;
cin >> a >> b;
h1 = h1 + (a * 8);
if (h1 < h2 && a <= b) {
cout << -1 << endl;
} else {
while (h1 < h2) {
h1 = (h1 + 12 * (a - b));
count++;
}
cout << count << endl;
}
}
|
### Prompt
Please create a solution in Cpp to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b, count;
count = 0;
cin >> h1 >> h2;
cin >> a >> b;
h1 = h1 + (a * 8);
if (h1 < h2 && a <= b) {
cout << -1 << endl;
} else {
while (h1 < h2) {
h1 = (h1 + 12 * (a - b));
count++;
}
cout << count << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int sum[100005];
int main() {
int h1, h2, a, b, k, x;
cin >> h1 >> h2 >> a >> b;
int num = h1 + a * 8;
if (num >= h2)
x = 0;
else if (a <= b)
x = -1;
else {
x = 1;
num -= b * 12;
for (int i = 1;; i++) {
num += a * 12;
if (num >= h2)
break;
else {
x++;
num -= b * 12;
}
}
}
cout << x << endl;
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int sum[100005];
int main() {
int h1, h2, a, b, k, x;
cin >> h1 >> h2 >> a >> b;
int num = h1 + a * 8;
if (num >= h2)
x = 0;
else if (a <= b)
x = -1;
else {
x = 1;
num -= b * 12;
for (int i = 1;; i++) {
num += a * 12;
if (num >= h2)
break;
else {
x++;
num -= b * 12;
}
}
}
cout << x << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
int main() {
int h1, h2, a, b, hour = 13, day = 0;
cin >> h1 >> h2 >> a >> b;
while (h1 < h2) {
hour = (hour + 1) % 24;
if (hour == 0) {
day++;
}
if (hour >= 10 && hour < 22) {
h1 += a;
} else {
h1 -= b;
}
if (day > 200000 || h1 < -INF) {
day = -1;
break;
}
}
cout << day << endl;
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
int main() {
int h1, h2, a, b, hour = 13, day = 0;
cin >> h1 >> h2 >> a >> b;
while (h1 < h2) {
hour = (hour + 1) % 24;
if (hour == 0) {
day++;
}
if (hour >= 10 && hour < 22) {
h1 += a;
} else {
h1 -= b;
}
if (day > 200000 || h1 < -INF) {
day = -1;
break;
}
}
cout << day << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
while (~scanf("%d%d%d%d", &h1, &h2, &a, &b)) {
if (h1 + 8 * a >= h2) {
puts("0");
continue;
}
int sum = 0, flag = 0;
h1 += 8 * a;
h1 -= 12 * b;
while (h1 < h2) {
h1 += 12 * a;
sum++;
if (h1 >= h2) break;
h1 -= 12 * b;
if (sum >= 10000 || h1 <= -1000000) {
flag = 1;
break;
}
}
if (flag)
puts("-1");
else
printf("%d\n", sum);
}
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
while (~scanf("%d%d%d%d", &h1, &h2, &a, &b)) {
if (h1 + 8 * a >= h2) {
puts("0");
continue;
}
int sum = 0, flag = 0;
h1 += 8 * a;
h1 -= 12 * b;
while (h1 < h2) {
h1 += 12 * a;
sum++;
if (h1 >= h2) break;
h1 -= 12 * b;
if (sum >= 10000 || h1 <= -1000000) {
flag = 1;
break;
}
}
if (flag)
puts("-1");
else
printf("%d\n", sum);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int solve() {
int ans = 0;
h1 += a * 8;
if (b >= a) {
if (h1 < h2) {
return -1;
} else {
return 0;
}
} else {
while (h1 < h2) {
if (h1 >= h2) {
return ans;
}
h1 -= b * 12;
ans++;
h1 += a * 12;
}
}
return ans;
}
int main() {
scanf("%d%d%d%d", &h1, &h2, &a, &b);
printf("%d\n", solve());
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int solve() {
int ans = 0;
h1 += a * 8;
if (b >= a) {
if (h1 < h2) {
return -1;
} else {
return 0;
}
} else {
while (h1 < h2) {
if (h1 >= h2) {
return ans;
}
h1 -= b * 12;
ans++;
h1 += a * 12;
}
}
return ans;
}
int main() {
scanf("%d%d%d%d", &h1, &h2, &a, &b);
printf("%d\n", solve());
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b, mor, nigh, day;
int main() {
while (cin >> h1 >> h2) {
cin >> a >> b;
if (a <= b) {
if (8 * a + h1 >= h2)
cout << "0\n";
else
cout << "-1\n";
continue;
}
bool flag = 1;
day = 0;
while (1) {
if (flag) {
nigh = h1 + 8 * a;
if (nigh >= h2) {
cout << "0\n";
break;
}
day++;
flag = 0;
continue;
}
mor = (nigh - 12 * b) ? (nigh - 12 * b) : 0;
nigh = mor + 12 * a;
if (nigh >= h2) {
cout << day << endl;
break;
}
day++;
}
}
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b, mor, nigh, day;
int main() {
while (cin >> h1 >> h2) {
cin >> a >> b;
if (a <= b) {
if (8 * a + h1 >= h2)
cout << "0\n";
else
cout << "-1\n";
continue;
}
bool flag = 1;
day = 0;
while (1) {
if (flag) {
nigh = h1 + 8 * a;
if (nigh >= h2) {
cout << "0\n";
break;
}
day++;
flag = 0;
continue;
}
mor = (nigh - 12 * b) ? (nigh - 12 * b) : 0;
nigh = mor + 12 * a;
if (nigh >= h2) {
cout << day << endl;
break;
}
day++;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, rd, rn, c = 0;
cin >> h1 >> h2 >> rd >> rn;
h1 += rd * 8;
int tryy = h1 + rd * 12 - rn * 12;
if (h1 >= h2) {
cout << "0";
return 0;
}
if (rn >= rd) {
cout << "-1";
return 0;
}
while (h1 < h2) {
h1 -= rn * 12;
h1 += rd * 4;
h1 += rd * 8;
c++;
}
cout << c;
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, rd, rn, c = 0;
cin >> h1 >> h2 >> rd >> rn;
h1 += rd * 8;
int tryy = h1 + rd * 12 - rn * 12;
if (h1 >= h2) {
cout << "0";
return 0;
}
if (rn >= rd) {
cout << "-1";
return 0;
}
while (h1 < h2) {
h1 -= rn * 12;
h1 += rd * 4;
h1 += rd * 8;
c++;
}
cout << c;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
int ans = 0;
if (b >= a) {
h1 = h1 + 8 * a;
if (h1 >= h2) {
cout << 0 << endl;
return 0;
}
if (h1 < h2) {
cout << -1 << endl;
return 0;
}
} else {
h1 = h1 + 8 * a;
if (h1 >= h2) {
cout << 0 << endl;
return 0;
}
h1 = h1 - 12 * b;
while (h1 < h2) {
ans++;
h1 += 12 * a;
if (h1 >= h2) {
cout << ans << endl;
return 0;
}
h1 -= 12 * b;
}
}
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
int ans = 0;
if (b >= a) {
h1 = h1 + 8 * a;
if (h1 >= h2) {
cout << 0 << endl;
return 0;
}
if (h1 < h2) {
cout << -1 << endl;
return 0;
}
} else {
h1 = h1 + 8 * a;
if (h1 >= h2) {
cout << 0 << endl;
return 0;
}
h1 = h1 - 12 * b;
while (h1 < h2) {
ans++;
h1 += 12 * a;
if (h1 >= h2) {
cout << ans << endl;
return 0;
}
h1 -= 12 * b;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout.setf(ios_base::fixed);
cout.precision(28);
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (b >= a) {
if (h1 + 8 * a >= h2) {
cout << 0;
return 0;
}
cout << -1;
return 0;
}
int d = 0;
while (true) {
if (d == 0) {
h1 += 8 * a;
} else {
h1 += 12 * a;
}
if (h1 >= h2) {
cout << d;
return 0;
}
h1 -= 12 * b;
++d;
}
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout.setf(ios_base::fixed);
cout.precision(28);
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (b >= a) {
if (h1 + 8 * a >= h2) {
cout << 0;
return 0;
}
cout << -1;
return 0;
}
int d = 0;
while (true) {
if (d == 0) {
h1 += 8 * a;
} else {
h1 += 12 * a;
}
if (h1 >= h2) {
cout << d;
return 0;
}
h1 -= 12 * b;
++d;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int h1, h2, a, b, c = 0;
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 < h2 && a <= b) {
cout << -1;
return 0;
}
while (h1 < h2) {
c++;
h1 -= 12 * b;
h1 += 12 * a;
if (h1 >= h2) break;
}
cout << c;
}
|
### Prompt
Please create a solution in CPP to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int h1, h2, a, b, c = 0;
cin >> h1 >> h2 >> a >> b;
h1 += 8 * a;
if (h1 < h2 && a <= b) {
cout << -1;
return 0;
}
while (h1 < h2) {
c++;
h1 -= 12 * b;
h1 += 12 * a;
if (h1 >= h2) break;
}
cout << c;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int x, y, a, b, ans;
int main() {
scanf("%d%d%d%d", &x, &y, &a, &b);
if (x + a * 8 < y && a <= b)
printf("-1");
else if (y <= x + a * 8)
printf("0");
else {
x = x + a * 8 - b * 12;
ans++;
while (x < y) {
x += a * 12;
if (x >= y) {
printf("%d", ans);
return 0;
}
x -= b * 12;
ans++;
}
printf("%d", ans);
}
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int x, y, a, b, ans;
int main() {
scanf("%d%d%d%d", &x, &y, &a, &b);
if (x + a * 8 < y && a <= b)
printf("-1");
else if (y <= x + a * 8)
printf("0");
else {
x = x + a * 8 - b * 12;
ans++;
while (x < y) {
x += a * 12;
if (x >= y) {
printf("%d", ans);
return 0;
}
x -= b * 12;
ans++;
}
printf("%d", ans);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool f(int x, int y) { return x > y; }
int main() {
int a, b, h1, h2, dia, z;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
dia = 0;
z = h1;
while (h1 < h2) {
h1 += 8 * a;
if (h1 >= h2) break;
h1 -= 12 * b;
dia++;
h1 += 4 * a;
if (h1 <= z) {
printf("-1\n");
return 0;
}
}
printf("%d\n", dia);
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool f(int x, int y) { return x > y; }
int main() {
int a, b, h1, h2, dia, z;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
dia = 0;
z = h1;
while (h1 < h2) {
h1 += 8 * a;
if (h1 >= h2) break;
h1 -= 12 * b;
dia++;
h1 += 4 * a;
if (h1 <= z) {
printf("-1\n");
return 0;
}
}
printf("%d\n", dia);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
int f = 1, d = 0;
h1 += (8 * a);
if (h1 >= h2) {
cout << "0";
return 0;
}
if (a <= b) {
cout << "-1";
return 0;
}
h1 -= (12 * b);
while (h1 < h2) {
h1 += (12 * a);
if (h1 >= h2) {
d++;
break;
}
h1 -= (12 * b);
d++;
}
cout << d << endl;
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
int f = 1, d = 0;
h1 += (8 * a);
if (h1 >= h2) {
cout << "0";
return 0;
}
if (a <= b) {
cout << "-1";
return 0;
}
h1 -= (12 * b);
while (h1 < h2) {
h1 += (12 * a);
if (h1 >= h2) {
d++;
break;
}
h1 -= (12 * b);
d++;
}
cout << d << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[100006];
bool cmp(int a, int b) { return (a > b); }
int a[100006];
map<int, int> m;
long long ans = 0;
int main() {
int h1, h2, a, b, ans = 0, c = 0;
cin >> h1 >> h2;
cin >> a >> b;
ans = h1;
ans += a * 8;
if (ans >= h2) {
cout << 0;
return 0;
}
while (a > b) {
if (ans >= h2) {
cout << c;
return 0;
}
c++;
ans -= 12 * b;
ans += 12 * a;
}
cout << -1;
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[100006];
bool cmp(int a, int b) { return (a > b); }
int a[100006];
map<int, int> m;
long long ans = 0;
int main() {
int h1, h2, a, b, ans = 0, c = 0;
cin >> h1 >> h2;
cin >> a >> b;
ans = h1;
ans += a * 8;
if (ans >= h2) {
cout << 0;
return 0;
}
while (a > b) {
if (ans >= h2) {
cout << c;
return 0;
}
c++;
ans -= 12 * b;
ans += 12 * a;
}
cout << -1;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, h1, h2, pos;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
pos = h1;
pos += a * 8;
if (pos >= h2) {
printf("0\n");
return 0;
}
pos -= 12 * b;
if (a <= b) {
printf("-1\n");
return 0;
}
int day = 1;
while (pos < h2) {
pos += 12 * a;
if (pos >= h2) {
break;
}
pos -= 12 * b;
day++;
}
printf("%d\n", day);
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, h1, h2, pos;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
pos = h1;
pos += a * 8;
if (pos >= h2) {
printf("0\n");
return 0;
}
pos -= 12 * b;
if (a <= b) {
printf("-1\n");
return 0;
}
int day = 1;
while (pos < h2) {
pos += 12 * a;
if (pos >= h2) {
break;
}
pos -= 12 * b;
day++;
}
printf("%d\n", day);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &a, &b);
if (a <= b && h1 + a * 8 < h2) {
printf("-1\n");
} else {
int cnt = 0;
int now = h1 - 4 * a;
while (now + a * 12 < h2) {
now += a * 12;
now -= b * 12;
cnt++;
}
printf("%d\n", cnt);
}
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &a, &b);
if (a <= b && h1 + a * 8 < h2) {
printf("-1\n");
} else {
int cnt = 0;
int now = h1 - 4 * a;
while (now + a * 12 < h2) {
now += a * 12;
now -= b * 12;
cnt++;
}
printf("%d\n", cnt);
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &a, &b);
int day = 0, pos = h1 + 8 * a;
if (pos >= h2)
printf("0\n");
else {
if (a <= b)
printf("-1\n");
else {
pos -= (12 * b);
day++;
while (1) {
pos += (12 * a);
if (pos >= h2)
break;
else {
pos -= (12 * b);
day++;
}
}
printf("%d\n", day);
}
}
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &a, &b);
int day = 0, pos = h1 + 8 * a;
if (pos >= h2)
printf("0\n");
else {
if (a <= b)
printf("-1\n");
else {
pos -= (12 * b);
day++;
while (1) {
pos += (12 * a);
if (pos >= h2)
break;
else {
pos -= (12 * b);
day++;
}
}
printf("%d\n", day);
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d;
int main() {
cin >> a >> b >> c >> d;
if (a + 8 * c >= b)
cout << "0";
else if (c > d) {
int num = b - a - 8 * c, den = 12 * (c - d);
cout << (num + den - 1) / den;
} else
cout << "-1";
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d;
int main() {
cin >> a >> b >> c >> d;
if (a + 8 * c >= b)
cout << "0";
else if (c > d) {
int num = b - a - 8 * c, den = 12 * (c - d);
cout << (num + den - 1) / den;
} else
cout << "-1";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h2 - h1 <= 8 * a) {
cout << 0 << endl;
} else if (b >= a) {
cout << -1 << endl;
} else {
int day = 0;
bool reached = false;
while (!reached) {
h1 += (a - b) * 12;
day++;
if (h2 - h1 <= 8 * a) reached = true;
}
cout << day << endl;
}
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h2 - h1 <= 8 * a) {
cout << 0 << endl;
} else if (b >= a) {
cout << -1 << endl;
} else {
int day = 0;
bool reached = false;
while (!reached) {
h1 += (a - b) * 12;
day++;
if (h2 - h1 <= 8 * a) reached = true;
}
cout << day << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int h1, h2, up, down;
cin >> h1 >> h2 >> up >> down;
if (up * 8 + h1 >= h2) {
cout << "0\n";
return;
}
if (up <= down) {
cout << "-1\n";
return;
}
int ans = 0;
h1 += up * 8;
h1 -= down * 12;
while (1) {
ans++;
h1 += up * 12;
if (h1 >= h2) break;
h1 -= down * 12;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
while (t--) solve();
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
int h1, h2, up, down;
cin >> h1 >> h2 >> up >> down;
if (up * 8 + h1 >= h2) {
cout << "0\n";
return;
}
if (up <= down) {
cout << "-1\n";
return;
}
int ans = 0;
h1 += up * 8;
h1 -= down * 12;
while (1) {
ans++;
h1 += up * 12;
if (h1 >= h2) break;
h1 -= down * 12;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
while (t--) solve();
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cout.sync_with_stdio(0);
cin.tie(0);
int a, b, h1, h2;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) {
cout << 0 << endl;
} else {
if (a > b) {
int n = h2 - h1 - 8 * a, d = 12 * (a - b);
cout << (n + d - 1) / d << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
cout.sync_with_stdio(0);
cin.tie(0);
int a, b, h1, h2;
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) {
cout << 0 << endl;
} else {
if (a > b) {
int n = h2 - h1 - 8 * a, d = 12 * (a - b);
cout << (n + d - 1) / d << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int H1, H2, H, A, B;
int main() {
scanf("%d%d%d%d", &H1, &H2, &A, &B);
H = H2 - H1 - A * 8;
if (H <= 0) {
printf("0");
return 0;
}
if (A <= B) {
printf("-1");
return 0;
}
printf("%d", (H - 1) / ((A - B) * 12) + 1);
}
|
### Prompt
Please formulate a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int H1, H2, H, A, B;
int main() {
scanf("%d%d%d%d", &H1, &H2, &A, &B);
H = H2 - H1 - A * 8;
if (H <= 0) {
printf("0");
return 0;
}
if (A <= B) {
printf("-1");
return 0;
}
printf("%d", (H - 1) / ((A - B) * 12) + 1);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if ((h1 + 8 * a) < h2 && a <= b) {
cout << "-1";
return 0;
}
int day = 0;
while (h1 < h2) {
if (day == 0)
h1 = h1 + 8 * a;
else
h1 = h1 + 12 * a;
if (h1 < h2)
day++;
else
break;
h1 = h1 - 12 * b;
}
cout << day;
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if ((h1 + 8 * a) < h2 && a <= b) {
cout << "-1";
return 0;
}
int day = 0;
while (h1 < h2) {
if (day == 0)
h1 = h1 + 8 * a;
else
h1 = h1 + 12 * a;
if (h1 < h2)
day++;
else
break;
h1 = h1 - 12 * b;
}
cout << day;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 1e5 + 100;
int h1, h2, a, b;
int Ac() {
h1 += a * 8;
if (h1 >= h2) {
return 0;
}
if (b >= a) return -1;
for (int i = 1; i <= 1e6; ++i) {
h1 -= 12 * b;
h1 += 12 * a;
if (h1 >= h2) return i;
}
return -1;
}
int main() {
while (~scanf("%d%d%d%d", &h1, &h2, &a, &b)) {
printf("%d\n", Ac());
}
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 1e5 + 100;
int h1, h2, a, b;
int Ac() {
h1 += a * 8;
if (h1 >= h2) {
return 0;
}
if (b >= a) return -1;
for (int i = 1; i <= 1e6; ++i) {
h1 -= 12 * b;
h1 += 12 * a;
if (h1 >= h2) return i;
}
return -1;
}
int main() {
while (~scanf("%d%d%d%d", &h1, &h2, &a, &b)) {
printf("%d\n", Ac());
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int a[100000 + 1];
int main() {
long long h1, h2, a, b;
scanf("%lld%lld", &h1, &h2);
scanf("%lld%lld", &a, &b);
h1 += 8 * a;
if (h1 >= h2) {
printf("0\n");
} else if (a > b) {
printf("%lld\n", (h2 - h1 + 12 * (a - b) - 1) / (12 * (a - b)));
} else {
printf("-1\n");
}
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100000 + 1];
int main() {
long long h1, h2, a, b;
scanf("%lld%lld", &h1, &h2);
scanf("%lld%lld", &a, &b);
h1 += 8 * a;
if (h1 >= h2) {
printf("0\n");
} else if (a > b) {
printf("%lld\n", (h2 - h1 + 12 * (a - b) - 1) / (12 * (a - b)));
} else {
printf("-1\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1061109567;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (c <= d) {
if (c * 8 + a >= b) {
puts("0");
} else
puts("-1");
return 0;
}
for (int i = 0;; i++) {
if (i == 0) {
a += 8 * c;
} else {
a += 12 * c;
}
if (a >= b) {
cout << i << endl;
return 0;
}
a -= 12 * d;
}
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1061109567;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (c <= d) {
if (c * 8 + a >= b) {
puts("0");
} else
puts("-1");
return 0;
}
for (int i = 0;; i++) {
if (i == 0) {
a += 8 * c;
} else {
a += 12 * c;
}
if (a >= b) {
cout << i << endl;
return 0;
}
a -= 12 * d;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h2 <= h1 + 8 * a)
cout << 0;
else if (a <= b)
cout << -1;
else
cout << (h2 - h1 + 4 * a - 12 * b - 1) / (12 * (a - b));
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (h2 <= h1 + 8 * a)
cout << 0;
else if (a <= b)
cout << -1;
else
cout << (h2 - h1 + 4 * a - 12 * b - 1) / (12 * (a - b));
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long h1, h2;
cin >> h1 >> h2;
long a, b;
cin >> a >> b;
if (h2 - h1 <= 8 * a)
cout << 0;
else if (b >= a) {
cout << -1;
return 0;
} else {
h1 += 8 * a;
long count = 0;
while (h1 < h2) {
h1 -= 12 * b;
h1 += 12 * a;
count++;
}
cout << count;
}
}
|
### Prompt
Please create a solution in Cpp to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long h1, h2;
cin >> h1 >> h2;
long a, b;
cin >> a >> b;
if (h2 - h1 <= 8 * a)
cout << 0;
else if (b >= a) {
cout << -1;
return 0;
} else {
h1 += 8 * a;
long count = 0;
while (h1 < h2) {
h1 -= 12 * b;
h1 += 12 * a;
count++;
}
cout << count;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) return cout << 0, 0;
if (a <= b) return cout << -1, 0;
cout << (h2 - h1 - 8 * a + 12 * a - 12 * b - 1) / (12 * a - 12 * b);
}
|
### Prompt
Generate a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> h1 >> h2 >> a >> b;
if (h1 + 8 * a >= h2) return cout << 0, 0;
if (a <= b) return cout << -1, 0;
cout << (h2 - h1 - 8 * a + 12 * a - 12 * b - 1) / (12 * a - 12 * b);
}
```
|
#include <bits/stdc++.h>
int main() {
int h1, h2, a, b, t, c;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
if (a <= b) {
if ((h2 - h1) <= 8 * a)
printf("0\n");
else
printf("-1\n");
} else {
if (8 * a >= (h2 - h1))
printf("0\n");
else {
t = 0;
c = h2 - h1 - (8 * a - 12 * b);
while (c > (12 * a)) {
c = c - (12 * a - 12 * b);
t++;
}
printf("%d", t + 1);
}
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int h1, h2, a, b, t, c;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
if (a <= b) {
if ((h2 - h1) <= 8 * a)
printf("0\n");
else
printf("-1\n");
} else {
if (8 * a >= (h2 - h1))
printf("0\n");
else {
t = 0;
c = h2 - h1 - (8 * a - 12 * b);
while (c > (12 * a)) {
c = c - (12 * a - 12 * b);
t++;
}
printf("%d", t + 1);
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const int N = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int x, y, a, b, ans = 0;
bool f = 1;
cin >> x >> y >> a >> b;
if (b >= a && (8 * a) + x < y)
cout << -1;
else {
while (true) {
if (f) {
f = 0;
x += 8 * a;
if (x >= y) break;
ans++;
x -= 12 * b;
} else {
x += 12 * a;
if (x >= y) break;
ans++;
x -= 12 * b;
}
}
cout << ans;
}
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const int N = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int x, y, a, b, ans = 0;
bool f = 1;
cin >> x >> y >> a >> b;
if (b >= a && (8 * a) + x < y)
cout << -1;
else {
while (true) {
if (f) {
f = 0;
x += 8 * a;
if (x >= y) break;
ans++;
x -= 12 * b;
} else {
x += 12 * a;
if (x >= y) break;
ans++;
x -= 12 * b;
}
}
cout << ans;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
void win() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
int ans = 0;
h1 = h1 - 4 * a;
int k = h1;
while (h1 < h2) {
h1 += a * 12;
if (h1 <= k) {
cout << -1;
return;
}
k = h1;
if (h1 >= h2) {
break;
}
h1 -= b * 12;
ans++;
}
cout << ans;
}
int main() {
int q = 1;
while (q--) {
win();
}
}
|
### Prompt
Please create a solution in CPP to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
void win() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
int ans = 0;
h1 = h1 - 4 * a;
int k = h1;
while (h1 < h2) {
h1 += a * 12;
if (h1 <= k) {
cout << -1;
return;
}
k = h1;
if (h1 >= h2) {
break;
}
h1 -= b * 12;
ans++;
}
cout << ans;
}
int main() {
int q = 1;
while (q--) {
win();
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (a == b) {
if ((h2 - h1 - 8 * a) <= 0)
cout << 0;
else {
cout << -1;
}
} else if (b > a) {
if (h2 - h1 - 8 * a <= 0)
cout << 0;
else
cout << -1;
} else {
if (h2 - h1 - 8 * a <= 0)
cout << 0;
else {
double d = (h2 - h1 - 8 * a) / (12 * (a - b));
cout << ceil(d);
}
}
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
double h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
if (a == b) {
if ((h2 - h1 - 8 * a) <= 0)
cout << 0;
else {
cout << -1;
}
} else if (b > a) {
if (h2 - h1 - 8 * a <= 0)
cout << 0;
else
cout << -1;
} else {
if (h2 - h1 - 8 * a <= 0)
cout << 0;
else {
double d = (h2 - h1 - 8 * a) / (12 * (a - b));
cout << ceil(d);
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
int res = 0;
if (h1 + 8 * a >= h2) {
cout << "0" << endl;
} else if (a > b) {
int num = h2 - h1 - 8 * a, den = 12 * (a - b);
cout << (num + den - 1) / den << endl;
} else {
cout << "-1" << endl;
}
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
int res = 0;
if (h1 + 8 * a >= h2) {
cout << "0" << endl;
} else if (a > b) {
int num = h2 - h1 - 8 * a, den = 12 * (a - b);
cout << (num + den - 1) / den << endl;
} else {
cout << "-1" << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
void func() {}
long long int power(long long int x, long long int y) {
long long int temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
int main() {
func();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
int x = abs(h1 - h2);
x -= a * 8;
if (x <= 0)
cout << "0"
<< "\n";
else {
if (a <= b)
cout << "-1"
<< "\n";
else {
long long int t = a * 12 - b * 12;
cout << ceil((double)x / t) << "\n";
}
}
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void func() {}
long long int power(long long int x, long long int y) {
long long int temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
int main() {
func();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
int x = abs(h1 - h2);
x -= a * 8;
if (x <= 0)
cout << "0"
<< "\n";
else {
if (a <= b)
cout << "-1"
<< "\n";
else {
long long int t = a * 12 - b * 12;
cout << ceil((double)x / t) << "\n";
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, hh, a, b, ans, d = 0, log = 0;
cin >> h >> hh >> a >> b;
ans = (h + (8 * a));
log = ans;
if (ans >= hh)
cout << "0" << endl;
else {
if (a <= b)
cout << -1 << endl;
else {
while (1) {
d++;
ans -= (12 * b);
ans += (12 * a);
if (ans >= hh) {
cout << d << endl;
break;
}
}
}
}
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, hh, a, b, ans, d = 0, log = 0;
cin >> h >> hh >> a >> b;
ans = (h + (8 * a));
log = ans;
if (ans >= hh)
cout << "0" << endl;
else {
if (a <= b)
cout << -1 << endl;
else {
while (1) {
d++;
ans -= (12 * b);
ans += (12 * a);
if (ans >= hh) {
cout << d << endl;
break;
}
}
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-9;
inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; }
int main() {
int h1, h2;
int a, b;
cin >> h1 >> h2 >> a >> b;
int t = 14;
int ans = 0;
while (true) {
int up = (22 - t) * a;
h1 += up;
if (h1 >= h2) {
cout << ans << '\n';
return 0;
}
ans++;
h1 -= 12 * b;
t = 10;
if (ans > 1 && b >= a) {
cout << -1 << '\n';
return 0;
}
}
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-9;
inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; }
int main() {
int h1, h2;
int a, b;
cin >> h1 >> h2 >> a >> b;
int t = 14;
int ans = 0;
while (true) {
int up = (22 - t) * a;
h1 += up;
if (h1 >= h2) {
cout << ans << '\n';
return 0;
}
ans++;
h1 -= 12 * b;
t = 10;
if (ans > 1 && b >= a) {
cout << -1 << '\n';
return 0;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
scanf("%d%d", &h1, &h2);
int diff = h2 - h1;
int a, b;
scanf("%d%d", &a, &b);
long long int f = 8 * a;
if (f >= diff) {
printf("%d\n", 0);
return 0;
}
diff -= f;
long long int dx = (a - b) * 12;
if (dx <= 0) {
printf("%d\n", -1);
return 0;
}
long long int ans = (diff + dx - 1) / dx;
cout << ans << "\n";
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
scanf("%d%d", &h1, &h2);
int diff = h2 - h1;
int a, b;
scanf("%d%d", &a, &b);
long long int f = 8 * a;
if (f >= diff) {
printf("%d\n", 0);
return 0;
}
diff -= f;
long long int dx = (a - b) * 12;
if (dx <= 0) {
printf("%d\n", -1);
return 0;
}
long long int ans = (diff + dx - 1) / dx;
cout << ans << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
if (h1 + 8 * a >= h2)
cout << 0;
else if (a > b) {
int n = h2 - h1 - 8 * a;
int d = 12 * (a - b);
cout << (n + d - 1) / d;
} else
cout << -1;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int h1, h2;
cin >> h1 >> h2;
int a, b;
cin >> a >> b;
if (h1 + 8 * a >= h2)
cout << 0;
else if (a > b) {
int n = h2 - h1 - 8 * a;
int d = 12 * (a - b);
cout << (n + d - 1) / d;
} else
cout << -1;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int ha, hb, a, b, res = 0, h1;
scanf("%d %d", &ha, &hb);
scanf("%d %d", &a, &b);
ha += a * 8;
h1 = ha;
if (ha >= hb) {
cout << 0 << endl;
return 0;
}
while (true) {
res++;
ha -= (b * 12);
ha += (a * 12);
if (ha >= hb) break;
if (ha <= h1) {
res = -1;
break;
}
}
cout << res << endl;
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int ha, hb, a, b, res = 0, h1;
scanf("%d %d", &ha, &hb);
scanf("%d %d", &a, &b);
ha += a * 8;
h1 = ha;
if (ha >= hb) {
cout << 0 << endl;
return 0;
}
while (true) {
res++;
ha -= (b * 12);
ha += (a * 12);
if (ha >= hb) break;
if (ha <= h1) {
res = -1;
break;
}
}
cout << res << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e1 + 4;
vector<int> circle;
bool vis[N];
int parent[N];
ll chk[N];
int color[N];
int tim[N];
int dis[N];
int position[N];
vector<int> adj[N];
vector<int> adj1[N];
vector<int> graph[N];
bool has_cycle;
int maxdis, maxnode, Totnode, depth = 1;
bool ok;
queue<int> q;
stack<int> stk;
vector<int> solution;
int indegree[N];
int go[N];
int to[N];
ll x1, x2, x3, x4, x5, x6;
string ss;
int gn, gk;
int main() {
int t = 1;
int cas = 0;
while (t--) {
ll n, m, i, j, cnt = 0, cnt1 = 0, cnt2 = 0, even = 0, odd = 0, len, k, r, l,
z = 0, x = 0, y = 0, flag = 0, sum = 0;
ll a = 0, b = 0, c = 0, d = 0, ans = 0, rem, quot, zero = 0, fst = 0,
null = 0, snd = 0, lst = 0, rone = 0, one = 0, pos = 0, neg = 0,
mn = INT_MAX, mx = INT_MIN;
char ch;
int h1, h2, m1, m2, h;
int velo1, velo2, ac1, ac2, tim, hour, mint, sec;
int node, edge, u, v, cost;
int bst, wrst;
double nd, ad, bd, xd, sumd = 0.00;
string str, str1 = "", str2 = "", str3 = "", strstore1 = "", strstore2 = "";
cin >> a >> b >> c >> d;
if (a + 8 * c >= b) {
cout << "0\n";
} else if (c <= d) {
cout << "-1\n";
} else {
x = b - a - 8 * c;
k = 12 * (c - d);
nd = x / (k * 1.0);
cout << ceil(nd) << endl;
}
}
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e1 + 4;
vector<int> circle;
bool vis[N];
int parent[N];
ll chk[N];
int color[N];
int tim[N];
int dis[N];
int position[N];
vector<int> adj[N];
vector<int> adj1[N];
vector<int> graph[N];
bool has_cycle;
int maxdis, maxnode, Totnode, depth = 1;
bool ok;
queue<int> q;
stack<int> stk;
vector<int> solution;
int indegree[N];
int go[N];
int to[N];
ll x1, x2, x3, x4, x5, x6;
string ss;
int gn, gk;
int main() {
int t = 1;
int cas = 0;
while (t--) {
ll n, m, i, j, cnt = 0, cnt1 = 0, cnt2 = 0, even = 0, odd = 0, len, k, r, l,
z = 0, x = 0, y = 0, flag = 0, sum = 0;
ll a = 0, b = 0, c = 0, d = 0, ans = 0, rem, quot, zero = 0, fst = 0,
null = 0, snd = 0, lst = 0, rone = 0, one = 0, pos = 0, neg = 0,
mn = INT_MAX, mx = INT_MIN;
char ch;
int h1, h2, m1, m2, h;
int velo1, velo2, ac1, ac2, tim, hour, mint, sec;
int node, edge, u, v, cost;
int bst, wrst;
double nd, ad, bd, xd, sumd = 0.00;
string str, str1 = "", str2 = "", str3 = "", strstore1 = "", strstore2 = "";
cin >> a >> b >> c >> d;
if (a + 8 * c >= b) {
cout << "0\n";
} else if (c <= d) {
cout << "-1\n";
} else {
x = b - a - 8 * c;
k = 12 * (c - d);
nd = x / (k * 1.0);
cout << ceil(nd) << endl;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, day = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
h1 += a * 8;
if (h1 >= h2)
printf("0\n");
else {
day++;
while (1) {
h1 -= b * 12;
h1 += a * 12;
if (h1 >= h2) {
printf("%d\n", day);
break;
}
if (b >= a) {
printf("-1\n");
break;
}
day++;
}
}
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, day = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
h1 += a * 8;
if (h1 >= h2)
printf("0\n");
else {
day++;
while (1) {
h1 -= b * 12;
h1 += a * 12;
if (h1 >= h2) {
printf("%d\n", day);
break;
}
if (b >= a) {
printf("-1\n");
break;
}
day++;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
int h = h2 - h1;
int ans = 0;
if (h - (8 * a) <= 0) {
cout << ans << endl;
return 0;
}
h -= (8 * a);
if (a - b <= 0) {
cout << -1 << endl;
return 0;
}
int ch = h;
while (ch > 0) {
ch -= ((a - b) * 12);
ans++;
}
cout << ans << endl;
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
cin >> h1 >> h2 >> a >> b;
int h = h2 - h1;
int ans = 0;
if (h - (8 * a) <= 0) {
cout << ans << endl;
return 0;
}
h -= (8 * a);
if (a - b <= 0) {
cout << -1 << endl;
return 0;
}
int ch = h;
while (ch > 0) {
ch -= ((a - b) * 12);
ans++;
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long x, y, a, b;
bool satisft(long long mid) {
long long p = a * 8LL - 12LL * b + 12LL * (a - b) * (mid - 1) + 12LL * a;
if (p >= y - x)
return true;
else
return false;
}
int main() {
cin >> x >> y >> a >> b;
long long lo = 0, high = 1000000, ans = -1;
if (x + 8LL * a >= y) {
printf("0\n");
return 0;
}
while (lo <= high) {
long long mid = (lo + high) >> 1;
if (satisft(mid)) {
high = mid - 1;
ans = mid;
} else {
lo = mid + 1;
}
}
cout << ans;
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long x, y, a, b;
bool satisft(long long mid) {
long long p = a * 8LL - 12LL * b + 12LL * (a - b) * (mid - 1) + 12LL * a;
if (p >= y - x)
return true;
else
return false;
}
int main() {
cin >> x >> y >> a >> b;
long long lo = 0, high = 1000000, ans = -1;
if (x + 8LL * a >= y) {
printf("0\n");
return 0;
}
while (lo <= high) {
long long mid = (lo + high) >> 1;
if (satisft(mid)) {
high = mid - 1;
ans = mid;
} else {
lo = mid + 1;
}
}
cout << ans;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int solve() {
int d = h2 - h1 - 8 * a;
int up = (a - b) * 12;
if (d <= 0) return 0;
if (up <= 0) return -1;
return d / up + !!(d % up);
}
int main() {
cin >> h1 >> h2 >> a >> b;
cout << solve() << "\n";
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int solve() {
int d = h2 - h1 - 8 * a;
int up = (a - b) * 12;
if (d <= 0) return 0;
if (up <= 0) return -1;
return d / up + !!(d % up);
}
int main() {
cin >> h1 >> h2 >> a >> b;
cout << solve() << "\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int main() {
int Begin, End, up, down;
scanf("%d%d%d%d", &Begin, &End, &up, &down);
int day0 = 8 * up;
int day;
if (up - down <= 0) {
if (End - Begin - day0 <= 0)
day = 0;
else
day = -1;
} else {
if (End - Begin - day0 <= 0)
day = 0;
else {
if ((End - Begin - day0) % (12 * (up - down)) == 0)
day = (End - Begin - day0) / (12 * (up - down));
else
day = (End - Begin - day0) / (12 * (up - down)) + 1;
}
}
cout << day;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int main() {
int Begin, End, up, down;
scanf("%d%d%d%d", &Begin, &End, &up, &down);
int day0 = 8 * up;
int day;
if (up - down <= 0) {
if (End - Begin - day0 <= 0)
day = 0;
else
day = -1;
} else {
if (End - Begin - day0 <= 0)
day = 0;
else {
if ((End - Begin - day0) % (12 * (up - down)) == 0)
day = (End - Begin - day0) / (12 * (up - down));
else
day = (End - Begin - day0) / (12 * (up - down)) + 1;
}
}
cout << day;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
cin >> h1 >> h2;
cin >> a >> b;
int k = 0;
if (h1 + 8 * a >= h2)
k = 0;
else if (a <= b) {
k = -1;
} else {
h1 = h1 + 8 * a;
while (h1 < h2) {
h1 = h1 + 12 * (a - b);
k++;
}
}
cout << k;
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
cin >> h1 >> h2;
cin >> a >> b;
int k = 0;
if (h1 + 8 * a >= h2)
k = 0;
else if (a <= b) {
k = -1;
} else {
h1 = h1 + 8 * a;
while (h1 < h2) {
h1 = h1 + 12 * (a - b);
k++;
}
}
cout << k;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int x = 0, a, b, A, B, z;
int main() {
cin >> B >> A >> a >> b;
A -= B;
if (x + 8 * a >= A) {
printf("0\n");
return 0;
}
if (a <= b) {
printf("-1\n");
return 0;
}
x += 8 * a;
x -= 12 * b;
z = 1;
while (x + 12 * a < A) {
x += 12 * (a - b);
++z;
}
printf("%d\n", z);
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int x = 0, a, b, A, B, z;
int main() {
cin >> B >> A >> a >> b;
A -= B;
if (x + 8 * a >= A) {
printf("0\n");
return 0;
}
if (a <= b) {
printf("-1\n");
return 0;
}
x += 8 * a;
x -= 12 * b;
z = 1;
while (x + 12 * a < A) {
x += 12 * (a - b);
++z;
}
printf("%d\n", z);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
long long int h1, h2;
cin >> h1 >> h2;
long long int a, b;
cin >> a >> b;
long long int start = 0;
long long int step = 1;
long long int height = h2 - h1;
long long int current = 0;
long long int day = 0;
long long int count = 0;
long long int cool = 1;
while (cool) {
current += (8 * a);
if (current >= height) {
break;
}
current -= (12 * b);
day++;
current += (4 * a);
if (current >= height) {
break;
}
count++;
if (count >= 1000100) {
printf("-1");
return 0;
}
}
cout << day;
return 0;
}
|
### Prompt
Create a solution in CPP for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
long long int h1, h2;
cin >> h1 >> h2;
long long int a, b;
cin >> a >> b;
long long int start = 0;
long long int step = 1;
long long int height = h2 - h1;
long long int current = 0;
long long int day = 0;
long long int count = 0;
long long int cool = 1;
while (cool) {
current += (8 * a);
if (current >= height) {
break;
}
current -= (12 * b);
day++;
current += (4 * a);
if (current >= height) {
break;
}
count++;
if (count >= 1000100) {
printf("-1");
return 0;
}
}
cout << day;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int main() {
scanf("%d%d%d%d", &h1, &h2, &a, &b);
if (h1 + 8 * a >= h2)
cout << 0 << endl;
else if (h1 + 8 * a < h2 && a <= b)
cout << -1 << endl;
else if (h1 + 8 * a < h2 && a > b) {
h1 += 8 * a;
h1 -= 12 * b;
int cnt = 1;
while (1) {
h1 += a * 12;
if (h1 >= h2)
break;
else
h1 -= b * 12;
cnt++;
}
cout << cnt << endl;
}
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b;
int main() {
scanf("%d%d%d%d", &h1, &h2, &a, &b);
if (h1 + 8 * a >= h2)
cout << 0 << endl;
else if (h1 + 8 * a < h2 && a <= b)
cout << -1 << endl;
else if (h1 + 8 * a < h2 && a > b) {
h1 += 8 * a;
h1 -= 12 * b;
int cnt = 1;
while (1) {
h1 += a * 12;
if (h1 >= h2)
break;
else
h1 -= b * 12;
cnt++;
}
cout << cnt << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, start = 14;
cin >> h1 >> h2 >> a >> b;
if (a <= b)
if (h1 + (22 - start) * a >= h2)
cout << 0;
else
cout << -1;
else {
int count = 0;
while (true) {
if (h1 + (22 - start) * a >= h2) {
cout << count;
break;
} else {
h1 += ((22 - start) * a - 12 * b);
start = 10;
}
count++;
}
}
}
|
### Prompt
Create a solution in cpp for the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, start = 14;
cin >> h1 >> h2 >> a >> b;
if (a <= b)
if (h1 + (22 - start) * a >= h2)
cout << 0;
else
cout << -1;
else {
int count = 0;
while (true) {
if (h1 + (22 - start) * a >= h2) {
cout << count;
break;
} else {
h1 += ((22 - start) * a - 12 * b);
start = 10;
}
count++;
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int f() {
int h1, h2, a, b, day = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
while (true) {
if (h1 + 8 * a >= h2) return day;
day++;
if (a <= b) return -1;
h1 += 12 * (a - b);
}
return -1;
}
int main() {
printf("%d\n", f());
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int f() {
int h1, h2, a, b, day = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
while (true) {
if (h1 + 8 * a >= h2) return day;
day++;
if (a <= b) return -1;
h1 += 12 * (a - b);
}
return -1;
}
int main() {
printf("%d\n", f());
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, day, night, i, j, k, l, cnt = 0;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
int prevh1 = h1;
while (h1 < h2) {
h1 = h1 + a * 8;
if (h1 >= h2) {
break;
}
h1 = h1 - b * 12 + a * 4;
if (h1 <= prevh1) {
cnt = -1;
break;
}
cnt++;
}
printf("%d\n", cnt);
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, day, night, i, j, k, l, cnt = 0;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
int prevh1 = h1;
while (h1 < h2) {
h1 = h1 + a * 8;
if (h1 >= h2) {
break;
}
h1 = h1 - b * 12 + a * 4;
if (h1 <= prevh1) {
cnt = -1;
break;
}
cnt++;
}
printf("%d\n", cnt);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, h, tr, ans;
double r;
while (4 == scanf("%d %d %d %d", &h1, &h2, &a, &b)) {
h = h2 - h1;
if (h <= 8 * a)
printf("0\n");
else {
tr = h1 + 8 * a - 12 * b;
if (a <= b)
printf("-1\n");
else {
ans = 1;
while (1) {
tr += 12 * a;
if (tr >= h2) break;
tr -= 12 * b;
ans++;
}
printf("%d\n", ans);
}
}
}
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b, h, tr, ans;
double r;
while (4 == scanf("%d %d %d %d", &h1, &h2, &a, &b)) {
h = h2 - h1;
if (h <= 8 * a)
printf("0\n");
else {
tr = h1 + 8 * a - 12 * b;
if (a <= b)
printf("-1\n");
else {
ans = 1;
while (1) {
tr += 12 * a;
if (tr >= h2) break;
tr -= 12 * b;
ans++;
}
printf("%d\n", ans);
}
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, u, d, z, x, cnt, a, b;
cin >> h1 >> h2 >> a >> b;
x = 8 * a;
if (h1 + x >= h2)
cout << 0 << endl;
else {
if (a > b) {
z = 12 * (a - b);
cnt = ceil((double)(h2 - (h1 + x)) / z);
cout << cnt << endl;
} else
cout << -1 << endl;
}
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, u, d, z, x, cnt, a, b;
cin >> h1 >> h2 >> a >> b;
x = 8 * a;
if (h1 + x >= h2)
cout << 0 << endl;
else {
if (a > b) {
z = 12 * (a - b);
cnt = ceil((double)(h2 - (h1 + x)) / z);
cout << cnt << endl;
} else
cout << -1 << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long h1, h2, a, b, d;
int main() {
cin >> h1 >> h2 >> a >> b;
d = h2 - h1;
if (a * 8ll >= d)
cout << 0;
else if (a <= b)
cout << -1;
else {
int day = 0;
for (int t = 14;; t++) {
if (t >= 10 && t < 22)
d -= a;
else
d += b;
if (d <= 0) break;
if (t == 24) t = 0, day++;
}
cout << day;
}
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long h1, h2, a, b, d;
int main() {
cin >> h1 >> h2 >> a >> b;
d = h2 - h1;
if (a * 8ll >= d)
cout << 0;
else if (a <= b)
cout << -1;
else {
int day = 0;
for (int t = 14;; t++) {
if (t >= 10 && t < 22)
d -= a;
else
d += b;
if (d <= 0) break;
if (t == 24) t = 0, day++;
}
cout << day;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5 + 5;
int main() {
int x, y, a, b;
cin >> x >> y >> a >> b;
if (x + 8 * a >= y)
puts("0");
else if (a > b) {
int num = y - x - 8 * a, den = 12 * (a - b);
cout << (num + den - 1) / den << endl;
} else
puts("-1");
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
Input
The first line contains two integers h1, h2 (1 β€ h1 < h2 β€ 105) β the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 β€ a, b β€ 105) β the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Output
Print the only integer k β the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
Examples
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
Note
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5 + 5;
int main() {
int x, y, a, b;
cin >> x >> y >> a >> b;
if (x + 8 * a >= y)
puts("0");
else if (a > b) {
int num = y - x - 8 * a, den = 12 * (a - b);
cout << (num + den - 1) / den << endl;
} else
puts("-1");
return 0;
}
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.