#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const int maxn = 1e7 + 10;
int n, k;
ll p[maxn], temp[maxn];
ll L;
ll get_price_left(int x)
{
ll res = 0;
int t = 0;
for (int i = 0; i < x; i ++)
{
//t ++;
//if (t == x || t % k == 0)
res = res + 2 * p[i];
}
return res;
}
ll get_price_right(int x)
{
ll res = 0;
int t = 0;
for (int i = n - 1; i >= n - x; i --)
{
//t ++;
//if (t == x || t % k == 0)
res = res + 2 * (L - p[i]);
}
return res;
}
long long delivery(int N, int K, int _L, int P[])
{
for (int i = 0; i < N; i ++)
p[i] = P[i];
n = N;
k = K;
L = _L;
ll ans = 0;
for (int i = 0; i < N; i ++)
{
ans = ans + 2 * min(P[i], _L - P[i]);
}
//cout << get_price_right(1) << endl;
///exit(0);
ll res = inf;
for (int i = 0; i < N; i ++)
{
ll val = get_price_left(i) + get_price_right(N - i);
//cout << i << " " << val << endl;
res = min(res, val);
//if (N - i - k >= 0)
//{
// val = get_price_left(i) + get_price_right(N - i - k) + L;
//res = min(res, val);
//}
}
assert(res >= ans);
return ans;
}
Compilation message
boxes.cpp: In function 'll get_price_left(int)':
boxes.cpp:16:9: warning: unused variable 't' [-Wunused-variable]
16 | int t = 0;
| ^
boxes.cpp: In function 'll get_price_right(int)':
boxes.cpp:29:9: warning: unused variable 't' [-Wunused-variable]
29 | int t = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2500 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2500 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2500 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2500 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |