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>
#define ll long long
#define f first
#define s second
using namespace std;
inline void io_setup(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
inline ll Min(ll a,ll b){ return a<b?a:b; }
inline ll Max(ll a,ll b){ return a>b?a:b; }
ll delivery(int n,int k,int L,int positions[]){
ll ans;
if(k==1){
ans = 0;
for(int i=0;i<n;i++){
ans += 2*Min(positions[i],L-positions[i]);
}
}else if(k==n){
pair<int,int> l,r;
for(int i=0;i<n;i++){
if(positions[i]<(L/2)){
l.f = Min(positions[i],l.f);
l.s = Max(positions[i],l.s);
}else{
r.f = Min(L-positions[i],r.f);
r.s = Max(L-positions[i],r.s);
}
}
ans = min(L,2*r.s+2*l.s);
}else{
ll CW[n];
ll ACW[n];
for(int i=0;i<n;i++){
if(i<k)CW[i]=Min(L,2*positions[i]);
else
CW[i] = CW[i-k]+Min(L,2*positions[i]);
}
for(int i=n-1;i>=0;i--){
if(i>=n-k)ACW[i] = Min(L,2*(L-positions[i]));
else ACW[i] = Min(L,2*(L-positions[i])) + ACW[i+k];
}
ll MIN = Min(CW[n-1],ACW[0]);
for(int i=1;i<n-1;i++){
MIN = Min(CW[i]+ACW[i+1],MIN);
}
ans = MIN;
}
return ans;
}
// int main(){
// io_setup();
// int arr[] = {1,2,5};
// cout << delivery(3,2,8,arr);
// }
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:28:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
l.f = Min(positions[i],l.f);
~~~^~~~~~~~~~~~~~~~~~
boxes.cpp:29:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
l.s = Max(positions[i],l.s);
~~~^~~~~~~~~~~~~~~~~~
boxes.cpp:31:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
r.f = Min(L-positions[i],r.f);
~~~^~~~~~~~~~~~~~~~~~~~
boxes.cpp:32:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
r.s = Max(L-positions[i],r.s);
~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |