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>
using namespace std;
const long long maxn=1e7+5;
long long dp1[maxn],dp2[maxn];
long long n,k,l;
long long a[maxn];
long long l1,l2;
long long ans=1e18;
void solve()
{
for(long long i=0;i<n;i++)
{
if(a[i]<=n/2)
{
long long h=max(1LL*0,i-k);
dp1[i]=dp1[h]+2*i;
}
}
int mid=0;
for(long long i=n-1;i>=0;i--)
{
if(a[i]>n/2)
{
long long h=i+k;
if(h>=n)h=0;
dp2[i]=dp2[h]+2*(n-i);
}
else {mid=i;break;}
}
for(int i=0;i<k;i++)
{
ans=min(ans,dp1[mid-i]+dp2[mid+k-i]);
}
}
long long delivery(int N, int K, int L, int p[])
{
n=N;
k=K;
l=L;
for(long long i=0;i<n;i++)
a[i]=p[i];
solve();
return 0;
}
Compilation message (stderr)
boxes.cpp: In function 'void solve()':
boxes.cpp:34:19: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
34 | else {mid=i;break;}
| ^
# | 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... |