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 <iostream>
using namespace std;
long long delivery( int N, int K, int L, int positions[] )
{
long long answer = 0;
int cnt = N, jnt = 0;
while( cnt > 0 ){
long long l = positions[ jnt ];
jnt += min( cnt, K );
cnt -= min( cnt, K );
long long r = positions[ jnt - 1 ];
long long mnl = min( l, L - l );
long long mnr = min( (L - r), r );
answer += min( L - l + mnl, r + mnr );
}
return answer;
}
/*
int main()
{
int N, K, L, positions[1000];
cin >> N >> K >> L;
for ( int i = 0; i < N; i ++ ){
cin >> positions[i];
}
cout << delivery( N, K, L, positions );
return 0;
}
/*
3 2 8
1 2 5
*/
/**/
Compilation message (stderr)
boxes.cpp:37:1: warning: "/*" within comment [-Wcomment]
/*
# | 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... |