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 ll long long int
using namespace std;
vector<ll> P;
vector<ll> Le,R,Ri;
ll n,k,l;
void pre_L(){
Le.push_back(0);
for(int i=0;i<k;i++) Le.push_back(2*P[i]);
for(int i=k;i<n;i++){
Le.push_back(2*P[i]+Le[i-k]);
}
Le.push_back(0);
}
void pre_R(){
for(int i=n-1;i>=n-k;i--) R.push_back(2*(l-P[i]));
for(int i=n-k-1;i>=0;i--){
R.push_back(2*(l-P[i])+R[n-k-1-i]);
}
Ri.push_back(0);
for(int i=n-1;i>=0;i--) Ri.push_back(R[i]);
Ri.push_back(0);
}
long long cal(int lb,int rb){
ll answer = ((rb-lb+1)/k)*l;
if((rb-lb+1)%k) answer += l;
answer += Le[lb-1];
answer += Ri[rb+1];
//cout << lb << " " << rb << " " << answer << "\n";
return answer;
}
long long delivery(int N, int K, int L, int p[]) {
for(int i=0;i<N;i++) P.push_back((ll)p[i]);
sort(P.begin(),P.end());
ll answer = 1000000000000000;
n=N;k=K;l=L;
pre_L();pre_R();
for(int i=1;i<=N;i++){
for(int j=i-1;j<=N;j++){
answer = min(answer,cal(i,j));
}
}
return answer;
}
Compilation message (stderr)
boxes.cpp: In function 'void pre_L()':
boxes.cpp:11:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
11 | for(int i=k;i<n;i++){
| ^
boxes.cpp: In function 'void pre_R()':
boxes.cpp:17:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
17 | for(int i=n-1;i>=n-k;i--) R.push_back(2*(l-P[i]));
| ~^~
boxes.cpp:18:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
18 | for(int i=n-k-1;i>=0;i--){
| ~~~^~
boxes.cpp:22:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
22 | for(int i=n-1;i>=0;i--) Ri.push_back(R[i]);
| ~^~
# | 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... |