이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
cout <<N<<" "<<K<<" "<<L<<endl;
deque<int> dq;
for(int i=0;i<N;i++){
dq.push_back(p[i]);
}
auto cost_right = [&](){
int ind = min(K,(int)dq.size())-1;
if(ind < 0)return 0;
return dq[ind];
};
auto cost_left = [&](){
int cnt = 0;
while(dq.front() == 0)cnt++;
if(cnt > K)return 0;
int ind = min(K-cnt,(int)dq.size()-cnt);
return N-dq[(int)dq.size()-ind];
};
int cnt = N;
long long res = 0;
while(cnt){
if(cost_right() <= cost_left()){
int x = K;
int dist = 0;
while(x-- && !dq.empty()){
dist = max(dist,dq.front()*2);
dq.pop_front();
}
res += dist;
}else{
int x = K;
int dist = 0;
while(x-- && !dq.empty()){
if(dq.front() == 0){
dist = max(dist,dq.front()*2);
dq.pop_front();
}else {
dist = max(dist,(N-dq.back())*2);
dq.pop_back();
}
}
res += dist;
}
}
return res;
}
# | 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... |