# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061156 | codefox | Boxes with souvenirs (IOI15_boxes) | C++14 | 1 ms | 348 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<bits/stdc++.h>
#include "boxes.h"
using namespace std;
#define ll long long
ll delivery(int N,int K,int L,int positions[])
{
deque<ll> first;
deque<ll> second;
for (int i = 0;i < N; i++)
{
if (positions[i]==0) continue;
if (positions[i]<=L/2) first.push_back(positions[i]);
else second.push_front(positions[i]);
}
ll sol = 0;
while (first.size() >= K)
{
int t = K;
sol += first[K-1]*2;
while (t--) first.pop_front();
}
while (second.size() >= K)
{
int t = K;
sol += (L-second[second.size()-K])*2;
while (t--) second.pop_back();
}
if (first.size()==0 && second.size()==0) return sol;
if (first.size() == 0) return sol+(L-second[0])*2;
if (second.size()==0) return sol+first.back()*2;
ll mn = 1e18;
if (first.size()+second.size()<=K) mn = L;
else
{
mn = min(mn, L+2*first[first.size()+second.size()-K]);
mn = min(mn, L+2*second[second.size()-(first.size()+second.size()-K)]);
}
mn = min(mn, 2*(first.back()+L-second.front()));
return sol+mn;
}
Compilation message (stderr)
# | 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... |