이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define F first
#define S second
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
long long delivery(int N, int K, int L, int p[]) {
priority_queue<ll> pq;
fo(i, N){
pq.push(p[i]);
}
ll ans = 1e18;
ll res = 0;
while(!pq.empty()){
ll pos = 0;
fo(i, K){
if(pq.empty()) break;
// deb2(res, pq.size());
ll next = pq.top();
pq.pop();
res+=min((next-pos+L)%L, (pos-next+L)%L);
// deb2((next-pos+L)%L, (pos-next+L)%L);
pos = next;
}
ll next = 0;
res+=min((next-pos+L)%L, (pos-next+L)%L);
}
ans = res;
fo(i, N){
pq.push(-p[i]);
}
while(!pq.empty()){
ll pos = 0;
fo(i, K){
if(pq.empty()) break;
ll next = -pq.top();
pq.pop();
res+=min((next-pos+L)%L, (pos-next+L)%L);
}
ll next = 0;
res+=min((next-pos+L)%L, (pos-next+L)%L);
}
ans = min(res, ans);
return 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... |