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 <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 2e9+7;
ll delivery(int n, int k, int l, int p[])
{
int x=0,y=n-1,cur,a,b;
ll ans=0;
while (x<=y)
{
cur=INF;a=69;b=420;
if (y-x+1<=k)
{
for (int i=x;i<y;++i)
cur=min(cur,(p[x]+l-p[y])*2);
cur=min({cur,l,p[y]*2,(l-p[x])*2});
ans+=cur;
break;
}
for (int i=0;i<k-1;++i)
if (cur>min(l,p[x+i]*2)+min(l,(l-p[y-k+i+2])*2))
{
cur=min(l,p[x+i]*2)+min(l,(l-p[y-k+i+2])*2);
a=x+i+1;
b=y-k+i+1;
}
if (cur>min(l,p[x+k-1]*2))
{
cur=min(l,p[x+k-1]*2);
a=x+k;
b=y;
}
if (cur>min(l,(l-p[y-k+1])*2))
{
cur=min(l,(l-p[y-k+1])*2);
a=x;
b=y-k;
}
//cout<<cur<<" "<<a<<" "<<b<<"\n";
ans+=cur;
x=a;
y=b;
}
return ans;
}
// int main()
// {
// int n,k,l;
// cin>>n>>k>>l;
// int p[n];
// for (int i=0;i<n;++i)
// cin>>p[i];
// cout<<delivery(n,k,l,p);
// }
# | 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... |