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>
using namespace std;
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
int N,K,L;
int clst(int x){
if(x>L/2) x=L-x;
return (x)*2;
}
long long delivery(signed _n, signed _k, signed _l, signed p[]) {
N=_n;
K=_k;
L=_l;
vector<int> a(N);
vector<int> marked(N);
for (int i = 0; i < N; i++) a[i]=p[i];
sort(a.begin(),a.end());
int sum=0;
int sumFULL=L;
int sumNOTFULL=0;
int lmt=N;
vector<pair<int,int>> res;
vector<int> res2;
vector<int> res3;
for (int i = 0; i < N; i++) { res.push_back({abs(L-2*a[i]),i}); }
sort(all(res));
for (int i = 0; i < sz(res); i++)
{
if(i<K) res3.push_back(res[i].second);
else res3.push_back(res[i].second);
res2.push_back(res[i].second);
}
sort(all(res2));
sort(all(res3));
for (int i = 0; i < sz(res2); i++) { if(a[res2[i]]>L/2) { lmt=i; break; } }
for (int i = lmt-1; i >= 0; i-=K) sumFULL+=a[res2[i]]*2;
for (int i = lmt; i < sz(res2); i+=K) sumFULL+=(L-a[res2[i]])*2;
for (int i = 0; i < sz(res3); i++) { if(a[res3[i]]>L/2) { lmt=i; break; } }
for (int i = lmt-1; i >= 0; i-=K) sumNOTFULL+=a[res3[i]]*2;
for (int i = lmt; i < sz(res3); i+=K) sumNOTFULL+=(L-a[res3[i]])*2;
sum+=min(sumFULL,sumNOTFULL);
return sum;
}
# | 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... |