# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
618911 | A_D | Boxes with souvenirs (IOI15_boxes) | C++14 | 1 ms | 340 KiB |
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>
const int N=1e7+10;
long long pre[N];
long long suf[N];
int hhhh[N];
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
for(int i=0;i<N;i++){
hhhh[i]=p[i];
}
sort(hhhh,hhhh+N);
for(int i=0;i<N;i++){
p[i]=hhhh[i];
}
long long ans=1e18;
long long me=0,cur=0,lst=0;
// cout<<5<<"\n";
for(int i=0;i<N;i++){
long long h=p[i];
me+=h-lst;
cur++;
pre[i]=me+min(h,L-h);
if(cur==K){
me+=min(h,L-h);
cur=0;
me+=h;
}
lst=p[i];
}
ans=pre[N-1];
me=0,cur=0,lst=L;
// cout<<5<<"\n";
for(int i=N-1;i>=0;i--){
long long h=p[i];
me+=abs(h-lst);
cur++;
suf[i]=me+min(h,L-h);
if(cur==K){
me+=min(h,L-h);
cur=0;
me+=N-h;
}
lst=p[i];
}
//cout<<5<<"\n";
for(int i=0;i<N-1;i++){
ans=min(ans,pre[i]+suf[i+1]);
}
// for(int i=0;i<N;i++)cout<<pre[i]<<" ";cout<<"\n";
// for(int i=0;i<N;i++)cout<<suf[i]<<" ";cout<<"\n";
return ans;
}
Compilation message (stderr)
# | 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... |