#include <bits/stdc++.h>
using namespace std;
const long long daug = 1000000000000000;
int n, h;
int I[10];
vector <int> V;
int c = 0;
long long kiek()
{
c++;
for(int i = 1; i<n; i++)
{
if(abs(I[i] - I[i-1]) > h) return daug;
}
long long ats = 0;
for(int i = 0; i<n; i++)
{
ats += abs(V[i] - I[i]);
}
return ats;
}
int main()
{
cin >> n >> h;
for(int i = 0; i<n; i++)
{
int x;
cin >> x;
V.push_back(x);
}
long long atsakymas = daug;
if(n >= 1)
{
for(I[0] = 0; I[0] <=4; I[0]++)
{
if(n == 1) atsakymas = min(atsakymas, kiek());
if(n >= 2)
{
for(I[1] = 0; I[1] <=4; I[1]++)
{
if(n == 2) atsakymas = min(atsakymas, kiek());
if(n >= 3)
{
for(I[2] = 0; I[2] <=4; I[2]++)
{
if(n == 3) atsakymas = min(atsakymas, kiek());
if(n >= 4)
{
for(I[3] = 0; I[3] <=4; I[3]++)
{
if(n == 4) atsakymas = min(atsakymas, kiek());
if(n >= 5)
{
for(I[4] = 0; I[4] <=4; I[4]++)
{
if(n == 5) atsakymas = min(atsakymas, kiek());
if(n >= 6)
{
for(I[5] = 0; I[5] <=4; I[5]++)
{
if(n == 6) atsakymas = min(atsakymas, kiek());
if(n >= 7)
{
for(I[6] = 0; I[6] <=4; I[6]++)
{
if(n == 7) atsakymas = min(atsakymas, kiek());
if(n >= 8)
{
for(I[7] = 0; I[7] <=4; I[7]++)
{
if(n == 8) atsakymas = min(atsakymas, kiek());
if(n >= 9)
{
for(I[8] = 0; I[8] <=4; I[8]++)
{
if(n == 9) atsakymas = min(atsakymas, kiek());
if(n >= 10)
{
for(I[9] = 0; I[9] <=4; I[9]++)
{
if(n == 10) atsakymas = min(atsakymas, kiek());
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
cout << atsakymas;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
133 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
131 ms |
408 KB |
Output is correct |
5 |
Correct |
132 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
432 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
1332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
133 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
131 ms |
408 KB |
Output is correct |
5 |
Correct |
132 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
432 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
8 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
133 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
131 ms |
408 KB |
Output is correct |
5 |
Correct |
132 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
432 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
8 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
133 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
131 ms |
408 KB |
Output is correct |
5 |
Correct |
132 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
432 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
8 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
133 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
131 ms |
408 KB |
Output is correct |
5 |
Correct |
132 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
432 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
8 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
344 KB |
Output is correct |
2 |
Correct |
133 ms |
424 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
131 ms |
408 KB |
Output is correct |
5 |
Correct |
132 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
432 KB |
Output is correct |
7 |
Correct |
27 ms |
344 KB |
Output is correct |
8 |
Incorrect |
8 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |