# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
307683 | kylych03 | Boxes with souvenirs (IOI15_boxes) | C++14 | 1 ms | 384 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"
//#include "grader.cpp"
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
sort(p, p+N);
vector <long long > a,b;
for(int i = 0; i < N; i++){
if(p[i] <= L/2)
a.push_back(p[i]);
else
b.push_back(L-p[i]);
}
sort(b.begin(), b.end());
long long res = 0;
for(int i = 0 ; i < a.size();i++){
if((i+1)% K == 0)
res += (a[i] * 2);
}
for(int i = 0 ; i < b.size();i++)
if((i+1)%K == 0)
res+=(b[i] * 2);
if(a.size()%K !=0)
res+=(a[a.size() - 1] * 2);
if(b.size()%K!=0)
res+=( b[b.size() - 1] * 2);
long long res1 = L;
while(K--) {
if(a.size()==0 && b.size()==0)
break;
if(a.size()==0){
b.pop_back();
continue;
}
if(b.size()==0){
a.pop_back();
continue;
}
if(a.back() > b.back())
a.pop_back();
else
b.pop_back();
}
for(int i = 0 ; i < a.size();i++){
if((i+1)% K == 0)
res1 += (a[i] * 2);
}
for(int i = 0 ; i < b.size();i++)
if((i+1)%K == 0)
res1+=(b[i] * 2);
if(a.size()%K !=0)
res1+=(a[a.size() - 1] * 2);
if(b.size()%K!=0)
res1+=( b[b.size() - 1] * 2);
if(res1 < res)
res= res1;
return res;
}
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... |