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 fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int MAX = 101010;
const int INF = 1e9;
const ll LINF = 1e18;
long long delivery(int N, int K, int L, int p[]) {
vector <ll> l, r;
for(int i = 0; i < N; i++) {
if(p[i] <= L / 2) l.eb(p[i]);
else r.eb(L-p[i]);
}
ll ans = 0;
while(!l.empty() && !r.empty() && l.back() + r.back() > L/2) {
ans += L;
for(int i = 0; i < K; i++) {
if(l.empty()) r.pop_back();
else if(r.empty()) l.pop_back();
else if(l.back() > r.back()) l.pop_back();
else r.pop_back();
}
}
while(!l.empty()) {
ans += 2 * l.back();
for(int i = 0; i < K; i++) if(!l.empty()) l.pop_back();
}
while(!r.empty()) {
ans += 2 * r.back();
for(int i = 0; i < K; i++) if(!r.empty()) r.pop_back();
}
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... |