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>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#include "boxes.h"
const ll N=1e7+99,inf=1e18;
ll n,t,ans,a[N],A[N],B[N];
ll delivery(int n, int k, int m, int p[]) {
ans=inf;
f(i,1,n+1) a[i]=p[i-1];
f(i,1,n+1){
A[i]=(i<k ? 0 : A[i-k])+a[i];
//eror(A[i-k]);
}
f_(i,n,1){
B[i]=B[i+k>n ? 0 : B[i-k]]+m-a[i];
}
//dbga(A,1,n+1);
//dbga(B,1,n+1);
if(k==n) minm(ans,1ll*m);
f(i,0,n+1) minm(ans,2ll*(A[i]+B[i+1]));
f(i,0,n-k+1){
minm(ans,2ll*(A[i]+B[i+k+1])+m);
}
return ans;
}
/*
int32_t main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n,k,m,b[10];
cin>>n>>k>>m;
f(i,0,n) cin>>b[i];
cout<<delivery(n,k,m,b);
}*/
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:28:17: warning: declaration of 'n' shadows a global declaration [-Wshadow]
28 | ll delivery(int n, int k, int m, int p[]) {
| ~~~~^
boxes.cpp:26:4: note: shadowed declaration is here
26 | ll n,t,ans,a[N],A[N],B[N];
| ^
# | 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... |