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;
typedef long long ll;
const int N = 1e7+2;
int n,k,l;
int pos[N];
ll kje1(){
ll sol = 0;
for(int i = 0; i < n; i++){
ll dod = 2*min(pos[i],(int)l-pos[i]);
sol += dod;
}
return sol;
}
ll kjen(){
int sol = l;
sol = min(sol,2*(l-pos[0]));
for(int i = 0; i < n-1; i++){
int sta = 2*pos[i]+2*(l-pos[i+1]);
sol = min(sol,sta);
}
sol = min(sol,2*pos[n-1]);
return sol;
}
ll inace(){
ll sol1 = 0;
int a = l/2, b = (l+1)/2;
for(int i = 0; i < n; i += k){
int kraj = min(i+k-1,n-1);
/// sad gledas range pos-ova od i do kraj
if(pos[kraj] <= a) sol1 += (ll)2*pos[kraj];
else if(pos[i] >= b) sol1 += (ll)2*(l-pos[i]);
else sol1 += l;
}
ll sol2 = 0;
a = l/2, b = (l+1)/2;
for(int i = n-1; i >= 0; i -= k){
int poc = max(0,i-k+1);
/// sad gledas range pos-ova od poc do i
if(pos[i] <= a) sol2 += (ll)2*pos[i];
else if(pos[poc] >= b) sol2 += (ll)2*(l-pos[poc]);
else sol2 += l;
}
return min(sol1,sol2);
}
ll delivery(int br1,int br2,int br3,int *positions){
n = br1;
k = br2;
l = br3;
for(int i = 0; i < n; i++) pos[i] = positions[i];
int sta = 0;
while(sta < n && pos[sta] == 0) sta++;
if(sta == n) return 0;
for(int i = 0; i < n-sta; i++) pos[i] = pos[i+sta];
n -= sta;
if(k == 1) return kje1();
if(k >= n) return kjen();
return inace();
}
# | 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... |