이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <vector>
#include <algorithm>
#define ll long long
#define ff first
#define ss second
#define ln "\n"
using namespace std;
vector<ll> pos;
ll n, k, l;
long long delivery(int N, int K, int L, int p[]) {
n=N; k=K; l=L;
pos.resize(n);
vector<pair<ll, ll>> dist(n);
for (ll i=0; i<n; i++){
pos[i] = p[i];
dist[i] = {min((ll)p[i], l-p[i]), i};
}
sort(dist.begin(), dist.end());
vector<ll> lsi, rsi;
ll li=2e18, ri=0;
for (ll i=dist.size()-k; i<(ll)dist.size(); i++){
li=min(li, pos[dist[i].ss]);
ri=max(ri, pos[dist[i].ss]);
}
for (ll i=0; i<(ll)dist.size(); i++){
if (pos[dist[i].ss]<=l/2){
lsi.push_back(dist[i].ss);
}else{
rsi.push_back(dist[i].ss);
}
}
ll ans=l;
ll aans=0;
for (ll i=lsi.size()-1; i>=0; i-=k){
aans+=pos[lsi[i]]*2;
}
for (ll i=rsi.size()-1; i>=0; i-=k){
aans+=(l-pos[rsi[i]])*2;
}
while (!lsi.empty() and pos[lsi.back()]>=li) {lsi.pop_back();}
// cout << ln;
while (!rsi.empty() and pos[rsi.back()]<=ri) {rsi.pop_back();}
// cout << ln;
// cout << li << " " << ri << ln;
for (ll i=lsi.size()-1; i>=0; i-=k){
ans+=pos[lsi[i]]*2;
}
for (ll i=rsi.size()-1; i>=0; i-=k){
ans+=(l-pos[rsi[i]])*2;
}
// cout << aans << " " << ans << ln;
return min(aans, ans);
}
# | 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... |