This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "boxes.h"
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define NN 10000007
#define pii pair<int, int>
using namespace std;
int n, k, a[NN], dp[NN], dp1[NN], ans, i;
deque<pii> d;
long long delivery(int N, int K, int L, int p[])
{
n = N, k = K;
for(i = 0; i < n; i++)
a[i] = p[i];
sort(a, a + n);
d.pb({0, -1});
for(i = 0; i < n; i++)
{
if(d.front().s == i - k - 1) d.pop_front();
dp[i] = 2 * a[i] + d.front().f;
while(d.size() && d.front().f >= dp[i]) d.pop_front();
d.pb({dp[i], i});
}
while(d.size()) d.pop_back();
d.pb({0, n});
for(i = n - 1; i >= 0; i--)
{
if(d.front().s == i + k + 1) d.pop_front();
dp1[i] = 2 * (L - a[i]) + d.front().f;
while(d.size() && d.front().f >= dp1[i]) d.pop_front();
d.pb({dp1[i], i});
}
ans = 1e18;
for(i = 0; i < n; i++)
ans = min(ans, dp[i] + dp1[(i + 1) % n]);
return ans;
}
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:36:11: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
36 | ans = 1e18;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |