# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032100 | SonicML | Boxes with souvenirs (IOI15_boxes) | C++14 | 0 ms | 0 KiB |
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 <iostream>
#include <algorithm>
#include "boxes.h"
using namespace std;
typedef long long ll;
int const NMAX = 1e7;
ll preA[1 + NMAX];
ll preB[1 + NMAX];
vector <int> a;
vector <int> b;
int centre = 0;
void buildPre(int k) {
for(int i = 0;i < a.size() && i < k;i++) {
preA[i] = 2 * a[i];
}
for(int i = k;i < a.size();i++) {
preA[i] = preA[i-k] + 2 * a[i];
}
for(int i = 0;i < b.size() && i < k;i++) {
preB[i] = 2 * b[i];
}
for(int i = k;i < b.size();i++) {
preB[i] = preB[i-k] + 2 * b[i];
}
}
ll delivery(int n, int k, int l, int positions[]) {
//cerr << "Damn, not here\n";
for(int i = 0;i < n;i++) {
int pos = positions[i];
if(l % 2 == 0 && pos == l / 2) {
centre = pos;
} else if(pos <= l / 2) {
a.push_back(pos);
} else {
b.push_back(l - pos);
}
}
//cerr << "Fourth Chaos Emerald\n";
sort(a.begin(), a.end());
sort(b.begin(), b.end());
buildPre(k);
//cerr << "I am all of me!\n";
ll ans = preA[a.size()-1] + preB[b.size()-1];
int limA = a.size()-1, limB = b.size()-1;
cerr << ans << '\n';
for(int round = 1;round < (n - 1) / k + 1;round++) {
for(int j = 0;j < k;j++) {
if(preA[limA] - preA[limA-1] < preB[limB] - preB[limB-1]) {
limA--;
} else {
limB--;
}
}
ll tans = 1LL * l * round + preA[limA] + preB[limB];
ans = min(ans, tans);
}
//cerr << "Just like taking candy from a baby, which is fine by me\n";
return ans;
}