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>
#define MIN -1
#define MAX 1e9+7
#define all(a) a.begin (), a.end ()
#define F first
#define S second
#define pb push_back
#define mk make_pair
#define mem(a, c) memset(a, 0, sizeof(a))
using namespace std;
typedef vector <int> v;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector <ll> vll;
long long delivery(int N, int K, int L, int p[]) {
ll s=0;
int n=N;
if(n==1){
for(int i=0;i<n;i++){
int aux=min(p[i], L-p[i]);
s+=+ll(2*aux);
}
return s;
}
ll aux1=0;
for(int i=0;i<n;i++){
s+=ll(p[i])-aux1;
aux1=ll(p[i]);
}
s+=min(p[n-1], L-p[n-1]);
ll s1=0;
aux1=L;
for(int i=n-1;i>=0;i--){
s1+=aux1-ll(p[i]);
aux1=ll(p[i]);
}
s1+=min(p[0], min(L-p[0], p[0]));
ll total =min(s,s1);
return total;
}/*
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;
static inline int _read() {
if (_charsNumber < 0) {
exit(1);
}
if (!_charsNumber || _currentChar == _charsNumber) {
_charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
_currentChar = 0;
}
if (_charsNumber <= 0) {
return -1;
}
return _buffer[_currentChar++];
}
static inline int _readInt() {
int c, x, s;
c = _read();
while (c <= 32) c = _read();
x = 0;
s = 1;
if (c == '-') {
s = -1;
c = _read();
}
while (c > 32) {
x *= 10;
x += c - '0';
c = _read();
}
if (s < 0) x = -x;
return x;
}
int main() {
_inputFile = fopen("boxes.in", "rb");
_outputFile = fopen("boxes.out", "w");
int N, K, L, i;
N = _readInt();
K = _readInt();
L = _readInt();
int *p = (int*)malloc(sizeof(int) * (unsigned int)N);
for (i = 0; i < N; i++) {
p[i] = _readInt();
}
int n, k, l;
int gg[n];
cin>>n>>k>>l;
for(int i=0;i<n;i++){
cin>>gg[i];
}
cout<<delivery(n, k, l, gg)<<endl;
fprintf(_outputFile, "%lld\n", delivery(N, K, L, p));
return 0;
}
*/
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:16:31: warning: unused parameter 'K' [-Wunused-parameter]
long long delivery(int N, int K, int L, int p[]) {
^
# | 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... |