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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;
bool DEBUG = 0;
const int MAXN = 10000005;
ll delivery(int n, int K, int L, int A[])
{
int a[n+1];
forn(i,0,n) a[i]=A[i];
a[n]=L;
ll l[n]{}, r[n]{};
forn(i,0,n){
l[i] = (i ? l[i-1]-min(a[i-1],L-a[i-1]) : 0) + a[i]-(i ? -a[i-1] : 0) + (i && i%K==0 ? 2*min(a[i-1],L-a[i-1]) : 0) + min(a[i],L-a[i]);
}
for(int i=n-1;i>=0;i--){
r[i] = (i<n-1 ? r[i+1]-min(a[i+1],L-a[i+1]) : 0) + (i<n-1 ? a[i+1] : L)-a[i] + (i<n-1 && (n-1-i)%K==0 ? 2*min(a[i+1],L-a[i+1]) : 0) + min(a[i],L-a[i]);
}
ll ans = min(l[n-1],r[0]);
//cout<<"i="<<0<<" cur="<<r[0]<<" ans="<<ans<<'\n';
forn(i,0,n-1){
ans = min(ans, l[i]+r[i+1]);
//cout<<"i="<<i+1<<" l="<<l[i]<<" r="<<r[i+1]<<" cur="<<l[i]+r[i+1]<<" ans="<<ans<<'\n';
}
//cout<<"i="<<n<<" cur="<<l[n-1]<<" ans="<<ans<<'\n';
return ans;
}
# | 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... |